jiemianNews/defs/get_news.py

23 lines
650 B
Python
Raw Permalink Normal View History

2022-08-02 13:14:10 +00:00
from typing import List
2022-08-02 15:24:13 +00:00
from ci import client
2022-08-02 13:14:10 +00:00
from defs.model import New
2022-08-02 15:24:13 +00:00
from defs.dump_data import get_time, set_time
2022-08-02 13:14:10 +00:00
2022-08-02 15:16:25 +00:00
async def get_news(time: int=None) -> List[New]:
if not time:
2022-08-02 15:24:13 +00:00
time = get_time()
2022-08-02 13:14:10 +00:00
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", [])]
2022-08-02 13:42:50 +00:00
update_time = time
2022-08-02 13:14:10 +00:00
for new in data:
if new.publish_time > update_time:
update_time = new.publish_time
2022-08-02 15:24:13 +00:00
set_time(update_time)
2022-08-02 13:14:10 +00:00
return data