PagerMaid_Plugins_Pyro/update_list.py

52 lines
1.7 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
2022-07-24 10:36:57 +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 = []
for file in main["files"]:
if file["filename"] == "list.json":
print(main['sha'] + " no need")
exit()
if "/main.py" in file["filename"]:
plugins.append(file["filename"].split("/")[0])
2022-07-26 06:11:31 +00:00
delete = bool(main['commit']['message'].startswith("Delete:"))
2022-07-24 10:47:11 +00:00
2022-07-24 10:36:57 +00:00
with open("list.json", "r", encoding="utf8") as f:
list_json = json.load(f)
for plugin in plugins:
exist = False
for plug_dict in list_json["list"]:
if plug_dict["name"] == plugin:
exist = True
2023-02-01 14:29:17 +00:00
old_version = decimal.Decimal(plug_dict["version"])
list_json["list"][list_json["list"].index(plug_dict)]["version"] = str(
old_version + decimal.Decimal("0.01")
)
2022-07-26 06:11:31 +00:00
if delete:
list_json["list"].remove(plug_dict)
2022-07-24 10:36:57 +00:00
break
if not exist:
2023-03-26 08:30:57 +00:00
short_des = main['commit']['message'].split("\nCo-authored-by")[0].strip()
2022-07-24 10:36:57 +00:00
list_json["list"].append(
2023-02-01 14:29:17 +00:00
{
"name": plugin,
"version": "1.0",
"section": "chat",
"maintainer": main['commit']['author']['name'],
"size": f"{os.path.getsize(f'{plugin}{os.sep}main.py') / 1000} kb",
"supported": True,
2023-03-26 08:30:57 +00:00
"des-short": short_des,
2023-02-01 14:29:17 +00:00
"des": "",
}
)
2022-07-24 10:36:57 +00:00
with open("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()
2022-07-24 10:36:57 +00:00
print(main['sha'] + " ok")