diff --git a/defs/format_time.py b/defs/format_time.py index da87acf..6a5a39c 100644 --- a/defs/format_time.py +++ b/defs/format_time.py @@ -19,3 +19,14 @@ def now_time() -> str: # UTC+8 ts = ts + timedelta(hours=8) return ts.strftime("%Y/%m/%d %H:%M:%S") + + +def strp_time(data: str) -> datetime: + # data = "2021-07-17T09:14:05Z" + if data: + ts = datetime.strptime(data, date_format) + else: + return datetime.now() + # UTC+8 + ts = ts + timedelta(hours=8) + return ts diff --git a/defs/source.py b/defs/source.py index 4df4b46..b7b6b40 100644 --- a/defs/source.py +++ b/defs/source.py @@ -31,12 +31,17 @@ async def update_data() -> None: if exists(f"data{sep}modules.json"): copyfile(f"data{sep}modules.json", f"data{sep}old_modules.json") async with AsyncClient(timeout=10.0, headers=headers, follow_redirects=True) as client: - data = await client.get("https://raw.githubusercontent.com/Xposed-Modules-Repo/modules/gh-pages/modules.json") + data = await client.get("https://modules.lsposed.org/modules.json") + modules_data = data.json() with open(f"data{sep}modules.json", "w", encoding="utf-8") as f: f.write(data.text) - data = data.json() old_modules = new_modules - new_modules = [Module(i) for i in data] + new_modules = [] + for i in modules_data: + try: + new_modules.append(Module(i)) + except Exception as e: + print(e) new_modules_index.clear() for i in new_modules: new_modules_index[i.name] = i @@ -56,7 +61,7 @@ async def download(url: str, name: str, pack_name: str) -> (str, str): async with AsyncClient(timeout=10.0, headers=headers, follow_redirects=True) as client: content = await client.get(url) if content.status_code == 404: - content = (await client.get(f"https://raw.githubusercontent.com/Xposed-Modules-Repo/modules/gh-pages/module/{pack_name}.json")).json() + content = (await client.get(f"https://modules.lsposed.org/module/{pack_name}.json")).json() data = Module(content) url = None if data.releases and data.releases[0].releaseAssets: diff --git a/defs/utils.py b/defs/utils.py index bda342c..228eaf7 100644 --- a/defs/utils.py +++ b/defs/utils.py @@ -1,5 +1,6 @@ +from datetime import datetime from typing import List -from defs.format_time import strf_time +from defs.format_time import strf_time, strp_time class Assets: @@ -14,6 +15,7 @@ class Release: self.url: str = data["url"] self.description: str = data["description"] self.publishedAt: str = strf_time(data["publishedAt"]) + self.publishedAtTime: datetime = strp_time(data["publishedAt"]) self.tagName: str = data["tagName"] self.isPrerelease: bool = data["isPrerelease"] assets = [] @@ -40,10 +42,13 @@ class Module: else: text.append(i["login"]) self.collaborators: List[str] = text - self.latestRelease: str = data["latestRelease"] + self.latestRelease: str = data.get("latestRelease") releases = [] if data["releases"]: releases.extend(Release(i) for i in data["releases"]) + if data.get("betaReleases"): + releases.extend(Release(i) for i in data["betaReleases"]) + releases.sort(key=lambda x: x.publishedAtTime, reverse=True) self.releases: List[Release] = releases self.updatedAt: str = releases[0].publishedAt if releases else strf_time(data["updatedAt"]) self.summary: str = data["summary"] or "" diff --git a/requirements.txt b/requirements.txt index f6c7be3..f2480be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -Pyrogram>=2.0.40 -Tgcrypto>=1.2.3 +Pyrogram>=2.0.59 +Tgcrypto>=1.2.4 httpx>=0.22.0 apscheduler>=3.8.1 sqlitedict>=2.0.0