import urllib.parse
from pyodide.http import open_url
import json
def searchCD(*ags, **kws):
input_test_element = Element("input_test")
input_word = input_test_element.element.value
input_test_element.clear() #処理後に入力フォームを空にする
keyword=repr(input_word)
test_text=''
request_url='https://app.rakuten.co.jp/services/api/BooksCD/Search/20170404'
APP_ID='1021810494159056409'
params={'artistName':keyword,
'sort':'-releaseDate',
'applicationId':APP_ID}
url=request_url+'?'+'artistName='+urllib.parse.quote(keyword)+r'&sort='+'-releaseDate'+r'&applicationId='+APP_ID
res = json.loads(open_url(url).read())
result=res
dic=[]
if 'error' in result:
test_text='失敗です!'
else:
if result['last'] !='':
suu=result['last']
else:
suu=0
for i in range(suu):
if (result['Items'][i]['Item']['smallImageUrl']!='' and result['Items'][i]['Item']['title']!='' and result['Items'][i]['Item']['itemUrl'] !=''):
dic.append(result['Items'][i]['Item']['title'])
dic.append(result['Items'][i]['Item']['itemUrl'])
if dic == []:
test_text='該当するアーティストがいません'
else:
dic1=dic[0::2]
dic2=dic[1::2]
for i in range(5):
pyscript.write(i,dic1[i])
pyscript.write(i+10,dic2[i])
pyscript.write("mes",test_text)
return