Archived
1
0
Fork 0
This commit is contained in:
yzhh 2022-06-19 20:39:52 +08:00
parent fb2edda4f2
commit 796a7854de
3 changed files with 6 additions and 4 deletions

View file

@ -2,6 +2,7 @@ import traceback
from typing import Union from typing import Union
import aiohttp import aiohttp
from aiofile import async_open
import filetype as ft import filetype as ft
from tenacity import retry, wait_fixed, stop_after_attempt from tenacity import retry, wait_fixed, stop_after_attempt
@ -60,8 +61,8 @@ async def download_to_cache(link: str) -> Union[str, bool]:
res = await resp.read() res = await resp.read()
ftt = ft.match(res).extension ftt = ft.match(res).extension
path = f'{random_cache_path()}.{ftt}' path = f'{random_cache_path()}.{ftt}'
with open(path, 'wb+') as file: async with async_open(path, 'wb+') as file:
file.write(res) await file.write(res)
return path return path
except: except:
Logger.error(traceback.format_exc()) Logger.error(traceback.format_exc())

View file

@ -37,8 +37,8 @@ async def search_csr(id=None): # 根据 ChemSpider 的 ID 查询 ChemSpider 的
if v.isdigit(): if v.isdigit():
value += int(v) # 加一起 value += int(v) # 加一起
wh = 500 * value // 100 wh = 500 * value // 100
if wh < 250: if wh < 500:
wh = 250 wh = 500
return {'name': name, 'image': f'https://www.chemspider.com/ImagesHandler.ashx?id={answer}&w={wh}&h={wh}'} return {'name': name, 'image': f'https://www.chemspider.com/ImagesHandler.ashx?id={answer}&w={wh}&h={wh}'}

View file

@ -18,3 +18,4 @@ feedparser
ffmpy ffmpy
google_play_scraper google_play_scraper
py-cpuinfo py-cpuinfo
aiofile