jiemianNews/defs/get_news.py

23 lines
687 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
2022-08-02 15:16:25 +00:00
async def get_news(time: int=None) -> List[New]:
if not time:
time = sqlite.get("update_time", int(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