mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
替换aiohttp为hettpx,用于异步获取公告列表
This commit is contained in:
parent
876fda38ad
commit
29d8d9337f
@ -2,6 +2,7 @@ import os
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from .aiorequests import get
|
||||
import aiohttp
|
||||
import asyncio
|
||||
import math
|
||||
@ -76,9 +77,8 @@ def cache(ttl=timedelta(hours=1), arg_key=None):
|
||||
@cache(ttl=timedelta(hours=3), arg_key='url')
|
||||
async def query_data(url):
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as resp:
|
||||
return await resp.json()
|
||||
resp = await get(url=url)
|
||||
return resp.json()
|
||||
except:
|
||||
pass
|
||||
return None
|
||||
@ -87,7 +87,8 @@ async def query_data(url):
|
||||
async def load_event_cn():
|
||||
result = await query_data(url=list_api)
|
||||
detail_result = await query_data(url=detail_api)
|
||||
if result and 'retcode' in result and result['retcode'] == 0 and detail_result and 'retcode' in detail_result and detail_result['retcode'] == 0:
|
||||
if result and 'retcode' in result and result['retcode'] == 0 and detail_result and 'retcode' in detail_result and \
|
||||
detail_result['retcode'] == 0:
|
||||
event_data['cn'] = []
|
||||
event_detail = {}
|
||||
for detail in detail_result['data']['list']:
|
||||
@ -127,7 +128,8 @@ async def load_event_cn():
|
||||
datelist = searchObj.groups() # ('2021', '9', '17')
|
||||
if datelist and len(datelist) >= 6:
|
||||
ctime = datetime.strptime(
|
||||
f'{datelist[0]}-{datelist[1]}-{datelist[2]} {datelist[3]}:{datelist[4]}:{datelist[5]}', r"%Y-%m-%d %H:%M:%S")
|
||||
f'{datelist[0]}-{datelist[1]}-{datelist[2]} {datelist[3]}:{datelist[4]}:{datelist[5]}',
|
||||
r"%Y-%m-%d %H:%M:%S")
|
||||
if start_time < ctime < end_time:
|
||||
start_time = ctime
|
||||
except Exception as e:
|
||||
@ -230,5 +232,6 @@ if __name__ == '__main__':
|
||||
async def main():
|
||||
await load_event_cn()
|
||||
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
|
Loading…
x
Reference in New Issue
Block a user