73 lines
2.1 KiB

import toml
import glob
from typing import Optional
from httpx import AsyncClient
import asyncio
with open("modinfo.toml", "r") as fp:
modinfo = toml.load(fp)
except OSError:
modinfo = {}
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"{modname}"
for k, v in {
"name": mod["name"],
"description": "XXX: update",
"link": link
modinfo["mods"][modname].setdefault(k, v)
if modinfo["mods"][modname]["description"] == "XXX: update" or modinfo["mods"][modname].get("icon") is None:
async def fetch_description(modname: str) -> tuple[str, dict]:
async with AsyncClient(headers={
"User-Agent": "Packwiz-Description-Generator/1.0 ("
}) as c:
print(f"[ + ] GET {modname}")
d = await c.get(f"{modname}")
data = d.json()
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["description"]
modinfo["mods"][modname]["icon"] = data["icon_url"]
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("", "w") as fp:
fp.write("# Mods list\n")
for modname in sorted(modinfo["mods"].keys()):
info = modinfo["mods"][modname]
fp.write(" * ")
fp.write(f'<img width="32" height="32" src="{info['icon']}">')
fp.write(f" **[{info['name']}]({info['link']})** - {info['description']}\n")