PagerMaid_Plugins_Pyro/update_list.py

62 lines
2.2 KiB
Python
Raw Normal View History

2022-07-24 10:36:57 +00:00
import json
import os
2023-02-01 14:29:17 +00:00
import decimal
2022-07-24 10:36:57 +00:00
from httpx import get
2023-02-01 14:29:17 +00:00
from update_des import update_des
2023-07-01 12:18:58 +00:00
main = get(
"https://api.github.com/repos/TeamPGM/PagerMaid_Plugins_Pyro/commits/v2"
).json()
2022-07-24 10:47:11 +00:00
plugins = []
2023-07-01 12:07:18 +00:00
alpha_plugins = []
list_json_start = ["", "alpha/"]
2022-07-24 10:47:11 +00:00
for file in main["files"]:
2023-07-01 12:07:18 +00:00
if "list.json" in file["filename"]:
2023-07-01 12:18:58 +00:00
print(main["sha"] + " no need")
2022-07-24 10:47:11 +00:00
exit()
if "/main.py" in file["filename"]:
2023-07-01 12:07:18 +00:00
if file["filename"].startswith("alpha"):
alpha_plugins.append(file["filename"].split("/")[1])
else:
plugins.append(file["filename"].split("/")[0])
2023-07-01 12:18:58 +00:00
delete = bool(main["commit"]["message"].startswith("Delete"))
2022-07-24 10:47:11 +00:00
2023-07-01 12:07:18 +00:00
for idx, plugins_ in enumerate([plugins, alpha_plugins]):
with open(f"{list_json_start[idx]}list.json", "r", encoding="utf8") as f:
list_json = json.load(f)
2023-07-01 12:31:50 +00:00
plugin_map = {i["name"]: i for i in list_json["list"]}
2023-07-01 12:07:18 +00:00
for plugin in plugins_:
2023-07-01 12:31:50 +00:00
if plugin in plugin_map:
if delete:
plugin_map.pop(plugin)
list_json["list"] = list(plugin_map.values())
continue
plug_dict = plugin_map[plugin]
old_version = decimal.Decimal(plug_dict["version"])
plug_dict["version"] = str(old_version + decimal.Decimal("0.01"))
plug_dict[
"size"
] = f"{os.path.getsize(f'{list_json_start[idx]}{plugin}{os.sep}main.py') / 1000} kb"
else:
2023-07-01 12:18:58 +00:00
short_des = main["commit"]["message"].split("\nCo-authored-by")[0].strip()
2023-07-01 12:07:18 +00:00
list_json["list"].append(
{
"name": plugin,
"version": "1.0",
"section": "chat",
2023-07-01 12:18:58 +00:00
"maintainer": main["commit"]["author"]["name"],
2023-07-01 12:07:18 +00:00
"size": f"{os.path.getsize(f'{list_json_start[idx]}{plugin}{os.sep}main.py') / 1000} kb",
"supported": True,
"des_short": short_des,
"des": "",
}
)
with open(f"{list_json_start[idx]}list.json", "w", encoding="utf8") as f:
json.dump(list_json, f, ensure_ascii=False, indent=4)
2023-02-01 14:29:17 +00:00
update_des()
2023-07-01 12:18:58 +00:00
print(main["sha"] + " ok")