Handle pixiv errors

This commit is contained in:
blank X 2020-12-24 23:07:23 +07:00
parent c897b3c598
commit 5916b87190
1 changed files with 7 additions and 6 deletions

View File

@ -77,12 +77,13 @@ async def saucenao(client, message):
if qs.get('illust_id'): if qs.get('illust_id'):
async with session.get(f'https://www.pixiv.net/touch/ajax/illust/details?illust_id={urlencode(qs["illust_id"][0])}', headers={'Accept': 'application/json'}) as resp: async with session.get(f'https://www.pixiv.net/touch/ajax/illust/details?illust_id={urlencode(qs["illust_id"][0])}', headers={'Accept': 'application/json'}) as resp:
json = await resp.json() json = await resp.json()
for i in ('url_big', 'url', 'url_s', 'url_placeholder', 'url_ss'): if json['body']:
pimg = json['body']['illust_details'].get(i) for i in ('url_big', 'url', 'url_s', 'url_placeholder', 'url_ss'):
if pimg: pimg = json['body']['illust_details'].get(i)
if await download_file(pimg, filename, url): if pimg:
to_image = True if await download_file(pimg, filename, url):
break to_image = True
break
if await download_file(url, filename): if await download_file(url, filename):
with open(filename) as file: with open(filename) as file:
soup = BeautifulSoup(file.read()) soup = BeautifulSoup(file.read())