<jupyter_start><jupyter_text>楽天市場のデータセットを取得する<jupyter_code>import json

with open("../credential.json") as fp:
    credential = json.load(fp)

import urllib.parse
import urllib.error

keyword="うさまる"
applicationId=credential["rakuten"]["applicationId"]
url=f"https://app.rakuten.co.jp/services/api/IchibaItem/Search/20170706" \
    f"?format=json" \
    f"&keyword={urllib.parse.quote(keyword)}" \
    f"&applicationId={applicationId}"
import urllib.request as request

contents = ""
try:
    response = request.urlopen(url)
    contents = response.read().decode()
    print(contents)
    response.close()
except urllib.error.HTTPError:
        print("not available")
else:
    pass
import pandas as pd
import json
temp2=json.loads(contents)
temp3=pd.json_normalize(temp2['Items'])
temp3<jupyter_output><empty_output><jupyter_text>楽天トラベル<jupyter_code># 検索する位置情報の設定
latitude="128440.51"
longitude="503172.21"
searchRadius="1"
url = f"https://app.rakuten.co.jp/services/api/Travel/SimpleHotelSearch/20170426" \
      f"?format=json" \
      f"&applicationId={applicationId}" \
      f"&latitude={latitude}" \
      f"&longitude={longitude}" \
      f"&searchRadius={searchRadius}"
url
try:
    response = request.urlopen(url)
    contents = response.read().decode()
    print(contents)
    response.close()
except urllib.error.HTTPError:
        print("not available")
else:
    pass
import pandas as pd
import json
temp2=json.loads(contents)
temp3=pd.json_normalize(temp2['hotels'], record_path='hotel')
temp2
temp3
next(temp3[1::2].itertuples())
columns = temp3.columns.copy()
columns, len(columns)

temp4 = pd.DataFrame([
    first[1:26] + last[26:]
    for first, last in zip(temp3[0::2].itertuples(), temp3[1::2].itertuples())
], columns=columns)

temp4<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15294117647058825, 'fraction_numerical': 0.03305322128851541, 'mean_word_length': 5.033783783783784, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '14942', 'license': 'MIT', 'n_tokens_mistral': 695, 'n_tokens_neox': 675, 'n_words': 98, 'path': '04_20210923/rakuten_api.ipynb', 'repo_name': 'yu-ichiro/2021_ds_economics', 'size': '1785'}