🐛 Try to fix so much update
This commit is contained in:
parent
c895b0be13
commit
cfa590aa54
1
ci.py
1
ci.py
@ -3,7 +3,6 @@ from configparser import RawConfigParser
|
||||
from os import sep, mkdir
|
||||
from os.path import exists
|
||||
|
||||
import pyromod.listen
|
||||
from pyrogram import Client
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from httpx import AsyncClient, get
|
||||
|
@ -1,5 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
date_format = "%Y-%m-%dT%H:%M:%SZ"
|
||||
|
||||
|
||||
@ -16,7 +15,7 @@ def strf_time(data: str) -> str:
|
||||
|
||||
def now_time() -> str:
|
||||
# UTC
|
||||
ts = datetime.utcnow()
|
||||
ts = datetime.now(timezone.utc)
|
||||
# UTC+8
|
||||
ts = ts + timedelta(hours=8)
|
||||
return ts.strftime("%Y/%m/%d %H:%M:%S")
|
||||
|
@ -58,10 +58,9 @@ def gen_update_msg(data: Module) -> TrackMessage:
|
||||
data.releases[0].description.replace(r"\r\n", "\n")[:250].strip())
|
||||
url = None
|
||||
name = None
|
||||
if data.releases:
|
||||
if data.releases[0].releaseAssets:
|
||||
url = data.releases[0].releaseAssets[0].url
|
||||
mime = data.releases[0].releaseAssets[0].name.split(".")[-1:][0]
|
||||
name = data.name.replace('.', '_') + "-" + data.latestRelease + "." + mime
|
||||
if data.releases and data.releases[0].releaseAssets:
|
||||
url = data.releases[0].releaseAssets[0].url
|
||||
mime = data.releases[0].releaseAssets[0].name.split(".")[-1:][0]
|
||||
name = data.name.replace('.', '_') + "-" + data.latestRelease + "." + mime
|
||||
button = gen_button(data)
|
||||
return TrackMessage(text, url, name, button)
|
||||
|
@ -15,13 +15,11 @@ old_modules_index: dict = {}
|
||||
if exists(f"data{sep}modules.json"):
|
||||
with open(f"data{sep}modules.json", "r", encoding="utf-8") as file:
|
||||
temp_data = load(file)
|
||||
for temp in temp_data:
|
||||
new_modules.append(Module(temp))
|
||||
new_modules.extend(Module(temp) for temp in temp_data)
|
||||
if exists(f"data{sep}old_modules.json"):
|
||||
with open(f"data{sep}old_modules.json", "r", encoding="utf-8") as file:
|
||||
temp_data = load(file)
|
||||
for temp in temp_data:
|
||||
old_modules.append(Module(temp))
|
||||
old_modules.extend(Module(temp) for temp in temp_data)
|
||||
new_modules_index = {i.name: i for i in new_modules}
|
||||
old_modules_index = {i.name: i.latestRelease for i in old_modules}
|
||||
|
||||
@ -35,20 +33,20 @@ async def update_data() -> None:
|
||||
f.write(data.text)
|
||||
data = data.json()
|
||||
old_modules = new_modules
|
||||
new_modules = []
|
||||
for i in data:
|
||||
new_modules.append(Module(i))
|
||||
new_modules_index = {i.name: i for i in new_modules}
|
||||
new_modules = [Module(i) for i in data]
|
||||
new_modules_index.clear()
|
||||
for i in new_modules:
|
||||
new_modules_index[i.name] = i
|
||||
sqlite["update_time"] = now_time()
|
||||
|
||||
|
||||
def compare() -> List[Module]:
|
||||
global old_modules_index
|
||||
data = []
|
||||
old_modules_index = {i.name: i.latestRelease for i in old_modules}
|
||||
for i in new_modules:
|
||||
if i.latestRelease != old_modules_index.get(i.name, ""):
|
||||
data.append(i)
|
||||
data = [i for i in new_modules if i.latestRelease != old_modules_index.get(i.name, "")]
|
||||
if len(data) > 10:
|
||||
await update_data()
|
||||
data = []
|
||||
return data
|
||||
|
||||
|
||||
@ -58,17 +56,15 @@ async def download(url: str, name: str, pack_name: str) -> (str, str):
|
||||
content = (await client.get(f"https://modules.lsposed.org/module/{pack_name}.json")).json()
|
||||
data = Module(content)
|
||||
url = None
|
||||
if data.releases:
|
||||
if data.releases[0].releaseAssets:
|
||||
url = data.releases[0].releaseAssets[0].url
|
||||
mime = data.releases[0].releaseAssets[0].name.split(".")[-1:][0]
|
||||
name = data.name.replace('.', '_') + "-" + data.latestRelease + "." + mime
|
||||
if url:
|
||||
content = await client.get(url)
|
||||
if content.status_code == 404:
|
||||
raise FileNotFoundError
|
||||
else:
|
||||
if data.releases and data.releases[0].releaseAssets:
|
||||
url = data.releases[0].releaseAssets[0].url
|
||||
mime = data.releases[0].releaseAssets[0].name.split(".")[-1:][0]
|
||||
name = data.name.replace('.', '_') + "-" + data.latestRelease + "." + mime
|
||||
if not url:
|
||||
raise FileNotFoundError
|
||||
content = await client.get(url)
|
||||
if content.status_code == 404:
|
||||
raise FileNotFoundError
|
||||
content = content.content
|
||||
with open(f"data{sep}{name}", 'wb') as f:
|
||||
f.write(content)
|
||||
|
@ -42,11 +42,7 @@ def gen_subs_msg(cid: int) -> str:
|
||||
data = value.get("subscribes", [])
|
||||
if cid in data:
|
||||
data_.append(key)
|
||||
if data_:
|
||||
text = subs_list_msg.format(from_list_to_name(data_))
|
||||
else:
|
||||
text = subs_list_no_msg
|
||||
return text
|
||||
return subs_list_msg.format(from_list_to_name(data_)) if data_ else subs_list_no_msg
|
||||
|
||||
|
||||
async def send_subs_msg(cid: int, data: Module, link: str):
|
||||
|
@ -18,8 +18,7 @@ class Release:
|
||||
self.isPrerelease: bool = data["isPrerelease"]
|
||||
assets = []
|
||||
if data["releaseAssets"]:
|
||||
for i in data["releaseAssets"]:
|
||||
assets.append(Assets(i))
|
||||
assets.extend(Assets(i) for i in data["releaseAssets"])
|
||||
self.releaseAssets: List[Assets] = assets
|
||||
self.releaseAssetsLen = len(assets)
|
||||
|
||||
@ -27,10 +26,11 @@ class Release:
|
||||
class Module:
|
||||
def __init__(self, data: dict):
|
||||
self.name: str = data["name"]
|
||||
self.description: str = data["description"] if data["description"] else ""
|
||||
self.url: str = data["url"] if data["url"] else ""
|
||||
self.homepageUrl: str = data["homepageUrl"] if data["homepageUrl"] else data["url"]
|
||||
self.sourceUrl: str = data["sourceUrl"] if data["sourceUrl"] else ""
|
||||
self.description: str = data["description"] or ""
|
||||
self.url: str = data["url"] or ""
|
||||
self.homepageUrl: str = data["homepageUrl"] or data["url"]
|
||||
|
||||
self.sourceUrl: str = data["sourceUrl"] or ""
|
||||
self.hide: bool = data["hide"]
|
||||
self.createdAt: str = strf_time(data["createdAt"])
|
||||
text = []
|
||||
@ -43,12 +43,11 @@ class Module:
|
||||
self.latestRelease: str = data["latestRelease"]
|
||||
releases = []
|
||||
if data["releases"]:
|
||||
for i in data["releases"]:
|
||||
releases.append(Release(i))
|
||||
releases.extend(Release(i) for i in data["releases"])
|
||||
self.releases: List[Release] = releases
|
||||
self.updatedAt: str = releases[0].publishedAt if releases else strf_time(data["updatedAt"])
|
||||
self.summary: str = data["summary"] if data["summary"] else ""
|
||||
self.scope: List[str] = data["scope"] if data["scope"] else []
|
||||
self.summary: str = data["summary"] or ""
|
||||
self.scope: List[str] = data["scope"] or []
|
||||
|
||||
|
||||
class TrackMessage:
|
||||
|
@ -35,10 +35,7 @@ async def inline_process(_: Client, query: InlineQuery):
|
||||
if module.scope:
|
||||
for i in module.scope:
|
||||
name += i
|
||||
skip = False
|
||||
for i in text:
|
||||
if i not in name:
|
||||
skip = True
|
||||
skip = any(i not in name for i in text)
|
||||
if not skip:
|
||||
data.append(InlineQueryResultArticle(
|
||||
(module.summary if module.summary else module.description) + " - " + module.name,
|
||||
|
@ -4,5 +4,5 @@ from pyrogram.types import Message
|
||||
|
||||
@Client.on_message(filters.incoming & filters.private &
|
||||
filters.command(["ping", ]))
|
||||
async def ping_check(bot: Client, message: Message):
|
||||
async def ping_check(_: Client, message: Message):
|
||||
await message.reply("poi ~", quote=True)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import contextlib
|
||||
import traceback
|
||||
from asyncio import sleep
|
||||
from os import remove
|
||||
@ -51,18 +52,16 @@ async def run_every_30_minute():
|
||||
parse_mode="html", )
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
try:
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
remove(file)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except FileNotFoundError:
|
||||
track_msg.url = None
|
||||
if not track_msg.url:
|
||||
try:
|
||||
msg = await send_track_msg(None, track_msg)
|
||||
except FloodWait as e:
|
||||
print(f"Send document flood - Sleep for {e.x} second(s)")
|
||||
await sleep(e.x + uniform(0.5, 1.0))
|
||||
print(f"Send document flood - Sleep for {e.value} second(s)")
|
||||
await sleep(e.value + uniform(0.5, 1.0))
|
||||
msg = await send_track_msg(None, track_msg)
|
||||
except ButtonUrlInvalid:
|
||||
print(f"Send button error")
|
||||
@ -82,5 +81,6 @@ async def run_every_30_minute():
|
||||
|
||||
@Client.on_message(filters.incoming & filters.private & filters.chat(admin_id) &
|
||||
filters.command(["force_update", ]))
|
||||
async def force_update(bot: Client, message: Message):
|
||||
async def force_update(_: Client, message: Message):
|
||||
await run_every_30_minute()
|
||||
await message.reply("Force update complete OK!")
|
||||
|
@ -1,6 +1,5 @@
|
||||
Pyrogram>=1.4.8
|
||||
Pyrogram>=2.0.35
|
||||
Tgcrypto>=1.2.3
|
||||
pyromod
|
||||
httpx>=0.22.0
|
||||
apscheduler>=3.8.1
|
||||
sqlitedict>=2.0.0
|
||||
|
Loading…
Reference in New Issue
Block a user