代码拉取完成,页面将自动刷新
import time
import json
import hashlib
import aiohttp
from amiya import run_amiya
from amiyabot.util import argv
from pluginsServer.src import server, api
AFDIAN_USER = argv('afdian-user')
AFDIAN_TOKEN = argv('afdian-token')
@server.server.app.get('/get_sponsors')
async def get_sponsors():
if not AFDIAN_TOKEN or not AFDIAN_USER:
return []
curr_page = 1
total_page = 1
sponsor_list = []
while curr_page <= total_page:
sec = int(time.time())
params = json.dumps({'page': curr_page})
data = {
'user_id': AFDIAN_USER,
'params': params,
'ts': sec,
'sign': hashlib.md5(
f'{AFDIAN_TOKEN}params{params}ts{sec}user_id{AFDIAN_USER}'.encode(encoding='utf-8')
).hexdigest(),
}
headers = {'Content-Type': 'application/json'}
url = 'https://afdian.com/api/open/query-sponsor'
async with aiohttp.ClientSession() as session:
async with session.post(url, data=json.dumps(data), headers=headers) as res:
res_content = await res.json()
if res_content['ec'] == 200:
total_page = res_content['data']['total_page']
sponsor_list += res_content['data']['list']
else:
break
curr_page += 1
return json.dumps(sponsor_list, ensure_ascii=False)
if __name__ == '__main__':
run_amiya(server.server.serve())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。