jiemianNews/defs/get_news.py
2022-08-02 21:42:50 +08:00

22 lines
647 B
Python

import time as time_
from typing import List
from ci import client, sqlite
from defs.model import New
async def get_news() -> List[New]:
time = sqlite.get("update_time", time_.time() - 600)
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
sqlite["update_time"] = update_time
return data