-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapi.py
21 lines (18 loc) · 778 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import aiohttp
import time
api_url = 'https://cn.bing.com/HPImageArchive.aspx'
async def bing(idx, UHD):
# https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN
# url = f'{idxurl}/HPImageArchive.aspx?format=js&idx={idx}&n=1&mkt=zh-CN'
parms = {'format': 'js', 'idx': idx, 'n': 1, 'mkt': 'zh-CN'}
# print('url:', url)
async with aiohttp.ClientSession() as session:
async with session.get(api_url, params=parms) as response:
data = await response.json()
print(data)
imgurl = data["images"][0]["url"]
if UHD:
imgurl = imgurl.replace('_1920x1080', '_UHD')
returl = 'https://cn.bing.com' + imgurl
print('imgurl:', returl)
return returl