use data.json
This commit is contained in:
parent
dad4f45f46
commit
1e3c984751
5
ci.py
5
ci.py
@ -1,16 +1,13 @@
|
||||
import json
|
||||
from configparser import RawConfigParser
|
||||
from os import sep, mkdir
|
||||
from os import mkdir
|
||||
from os.path import exists
|
||||
|
||||
from pyrogram import Client
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from httpx import AsyncClient
|
||||
from sqlitedict import SqliteDict
|
||||
|
||||
if not exists("data"):
|
||||
mkdir("data")
|
||||
sqlite = SqliteDict(f"data{sep}data.sqlite", encode=json.dumps, decode=json.loads, autocommit=True)
|
||||
# data.sqlite 结构如下:
|
||||
# {
|
||||
# "update_time": int,
|
||||
|
16
defs/dump_data.py
Normal file
16
defs/dump_data.py
Normal file
@ -0,0 +1,16 @@
|
||||
import json
|
||||
import time as time_
|
||||
from os.path import exists
|
||||
|
||||
|
||||
def get_time() -> int:
|
||||
if exists("data.json"):
|
||||
with open("data.json", "r") as f:
|
||||
data = json.load(f)
|
||||
return data.get("update_time", int(time_.time()) - 600)
|
||||
return int(time_.time()) - 600
|
||||
|
||||
|
||||
def set_time(time: int) -> None:
|
||||
with open("data.json", "w") as f:
|
||||
json.dump({"update_time": time}, f)
|
@ -1,13 +1,13 @@
|
||||
import time as time_
|
||||
from typing import List
|
||||
|
||||
from ci import client, sqlite
|
||||
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 = sqlite.get("update_time", int(time_.time()) - 600)
|
||||
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:
|
||||
@ -18,5 +18,5 @@ async def get_news(time: int=None) -> List[New]:
|
||||
for new in data:
|
||||
if new.publish_time > update_time:
|
||||
update_time = new.publish_time
|
||||
sqlite["update_time"] = update_time
|
||||
set_time(update_time)
|
||||
return data
|
||||
|
@ -2,5 +2,4 @@ Pyrogram==2.0.35
|
||||
Tgcrypto>=1.2.3
|
||||
httpx>=0.22.0
|
||||
apscheduler>=3.8.1
|
||||
sqlitedict>=2.0.0
|
||||
pytz
|
||||
|
Loading…
Reference in New Issue
Block a user