jiemianNews/defs/get_news.py
2022-08-02 23:24:13 +08:00

23 lines
650 B
Python

from typing import List
from ci import client
from defs.model import New
from defs.dump_data import get_time, set_time
async def get_news(time: int=None) -> List[New]:
if not time:
time = get_time()
url = f"https://papi.jiemian.com/page/api/kuaixun/getLastest?cid=1325kb&end_time={time}&tagid=1325"
data = await client.get(url)
if data.status_code != 200:
return []
data = data.json()
data = [New(**i) for i in data.get("result", [])]
update_time = time
for new in data:
if new.publish_time > update_time:
update_time = new.publish_time
set_time(update_time)
return data