51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from os import sep
|
|
from os.path import exists
|
|
from shutil import copyfile
|
|
from typing import List
|
|
|
|
from ci import client, sqlite
|
|
from json import load
|
|
from defs.format_time import now_time
|
|
from defs.utils import Module
|
|
|
|
new_modules: List[Module] = []
|
|
old_modules: List[Module] = []
|
|
if exists(f"data{sep}modules.json"):
|
|
with open(f"data{sep}modules.json", "r", encoding="utf-8") as file:
|
|
new_modules = load(file)
|
|
if exists(f"data{sep}old_modules.json"):
|
|
with open(f"data{sep}old_modules.json", "r", encoding="utf-8") as file:
|
|
old_modules = load(file)
|
|
|
|
|
|
async def update_data() -> None:
|
|
global new_modules, old_modules
|
|
if exists(f"data{sep}modules.json"):
|
|
copyfile(f"data{sep}modules.json", f"data{sep}old_modules.json")
|
|
data = await client.get("https://modules.lsposed.org/modules.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 = []
|
|
for i in data:
|
|
new_modules.append(Module(i))
|
|
sqlite["update_time"] = now_time()
|
|
|
|
|
|
def compare() -> List[Module]:
|
|
data = []
|
|
old_data = {i.name: i.latestRelease for i in old_modules}
|
|
for i in new_modules:
|
|
if i.latestRelease != old_data.get(i.name, ""):
|
|
data.append(i)
|
|
return data
|
|
|
|
|
|
async def download(url: str, name: str) -> str:
|
|
content = await client.get(url)
|
|
content = content.content
|
|
with open(f"data{sep}{name}", 'wb') as f:
|
|
f.write(content)
|
|
return f"data{sep}{name}"
|