2024-08-02 17:28:04 +03:00
|
|
|
import toml
|
|
|
|
import glob
|
|
|
|
from typing import Optional
|
|
|
|
from httpx import AsyncClient
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open("modinfo.toml", "r") as fp:
|
|
|
|
modinfo = toml.load(fp)
|
|
|
|
except OSError:
|
|
|
|
modinfo = { "mods": {} }
|
|
|
|
|
|
|
|
|
|
|
|
mods = {}
|
|
|
|
name_list: list[str] = []
|
|
|
|
for filename in glob.glob("mods/*.pw.toml"):
|
|
|
|
modname = filename.removesuffix(".pw.toml").split("/", 1)[1]
|
|
|
|
with open(filename, "r") as fp:
|
|
|
|
mod = mods[modname] = toml.load(fp)
|
|
|
|
|
|
|
|
modinfo["mods"].setdefault(modname, {})
|
|
|
|
|
|
|
|
link: Optional[str] = None
|
|
|
|
if "modrinth" in mod["update"]:
|
|
|
|
link = f"https://modrinth.com/mod/{modname}"
|
|
|
|
|
|
|
|
for k, v in {
|
|
|
|
"name": mod["name"],
|
|
|
|
"description": "XXX: update",
|
2024-08-09 14:09:36 +03:00
|
|
|
"link": link,
|
|
|
|
"side": mod.get("side", "unknown"),
|
|
|
|
"optional": mod.get("option", {}).get("optional", False)
|
2024-08-02 17:28:04 +03:00
|
|
|
}.items():
|
|
|
|
modinfo["mods"][modname].setdefault(k, v)
|
|
|
|
|
|
|
|
if modinfo["mods"][modname]["description"] == "XXX: update" or modinfo["mods"][modname].get("icon") is None:
|
|
|
|
name_list.append(modname)
|
|
|
|
|
|
|
|
async def fetch_description(modname: str) -> tuple[str, dict]:
|
|
|
|
async with AsyncClient(headers={
|
|
|
|
"User-Agent": "Packwiz-Description-Generator/1.0 (hatkidchan@gmail.com)"
|
|
|
|
}) as c:
|
|
|
|
print(f"[ + ] GET {modname}")
|
|
|
|
try:
|
|
|
|
d = await c.get(f"https://api.modrinth.com/v2/project/{modname}")
|
|
|
|
data = d.json()
|
|
|
|
except Exception:
|
|
|
|
return modname, {}
|
|
|
|
return modname, data
|
|
|
|
|
|
|
|
async def update_descriptions():
|
|
|
|
result = await asyncio.gather(*[
|
|
|
|
fetch_description(modname) for modname in name_list
|
|
|
|
])
|
|
|
|
for modname, data in result:
|
|
|
|
modinfo["mods"][modname]["description"] = data.get("description", "")
|
|
|
|
modinfo["mods"][modname]["icon"] = data.get("icon_url", "")
|
|
|
|
|
|
|
|
asyncio.run(update_descriptions())
|
|
|
|
|
|
|
|
for mod in modinfo["mods"]:
|
|
|
|
if mod not in mods:
|
|
|
|
modinfo["mods"][mod]["removed"] = True
|
|
|
|
|
|
|
|
with open("modinfo.toml", "w") as fp:
|
|
|
|
toml.dump(modinfo, fp)
|
|
|
|
|
|
|
|
|
|
|
|
with open("README.md", "w") as fp:
|
|
|
|
fp.write("# Mods list\n")
|
|
|
|
for modname in sorted(modinfo["mods"].keys()):
|
|
|
|
info = modinfo["mods"][modname]
|
2024-08-09 14:09:36 +03:00
|
|
|
tags = []
|
|
|
|
if info.get("optional", False):
|
|
|
|
tags.append(("O", "optional"))
|
|
|
|
side = info.get("side", "unknown")
|
|
|
|
if side == "client":
|
|
|
|
tags.append(("CO", "side:client"))
|
|
|
|
elif side == "server":
|
|
|
|
tags.append(("SO", "side:server"))
|
|
|
|
elif side == "both":
|
|
|
|
tags.append(("CS", "side:both"))
|
|
|
|
|
2024-08-04 22:22:38 +03:00
|
|
|
try:
|
|
|
|
fp.write(" * ")
|
|
|
|
fp.write(f'<img width="32" height="32" src="{info['icon']}">')
|
2024-08-09 14:09:36 +03:00
|
|
|
fp.write(str.join("", [
|
|
|
|
f"[<abbr title=\"{tag[1]}\">{tag[0]}</abbr>]"
|
|
|
|
for tag in tags
|
|
|
|
]))
|
|
|
|
fp.write(f" **[{info['name']}]({info['link']})**")
|
|
|
|
fp.write(f" - {info['description']}\n")
|
2024-08-04 22:22:38 +03:00
|
|
|
except Exception as e:
|
|
|
|
print(f"Err: {e!r} for {modname = }")
|
|
|
|
raise
|