jiemianNews/defs/get_news.py

22 lines
647 B
Python
Raw Normal View History

2022-08-02 13:40:57 +00:00
import time as time_
2022-08-02 13:14:10 +00:00
from typing import List
from ci import client, sqlite
from defs.model import New
async def get_news() -> List[New]:
2022-08-02 13:40:57 +00:00
time = sqlite.get("update_time", time_.time() - 600)
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
sqlite["update_time"] = update_time
return data