posspack/.forgejo/scripts/update-wiki.py
Ashley Graves ab73dcbff0
Some checks failed
Update wiki / test (push) Failing after 16s
test
2024-08-01 01:14:25 +02:00

100 lines
2.5 KiB
Python

#!/usr/bin/env python
from pip._vendor import requests
from pip._vendor import tomli
import glob
import os
def noop():
return
mods = dict()
count = dict()
count["server"] = 0
count["client"] = 0
count["both"] = 0
for mod in glob.glob("pack/mods/*.toml"):
with open(mod, "r") as f:
data = tomli.load(f)
moddata = dict()
moddata["url"] = ""
if "modrinth" in data["update"]:
id = data["update"]["modrinth"]["mod-id"]
moddata["id"] = id
moddata["url"] = "https://modrinth.com/mod/" + id
moddata["site"] = "Modrinth"
data = requests.get("https://api.modrinth.com/v2/project/" + id).json()
print(data)
exit
elif "curseforge" in data["update"]:
moddata["url"] = "https://legacy.curseforge.com/projects/" + str(data["update"]["curseforge"]["project-id"])
moddata["site"] = "CurseForge"
count[data["side"]] += 1
moddata["side"] = data["side"]
mods[data["name"]] = moddata
with open("wiki/Modlist.md", "w") as f:
f.write("## Total Count\r\n")
f.write("<table>")
f.write("\r\n<tr>")
f.write("<th>Side</th>")
f.write("<th>Count</th>")
f.write("</tr>\r\n")
f.write("<tr>")
f.write("<td>Total</td>")
f.write("<td>" + str(count["server"] + count["client"] + count["both"]) + "</td>")
f.write("</tr>\r\n")
f.write("<tr>")
f.write("<td>Shared</td>")
f.write("<td>" + str(count["both"]) + "</td>")
f.write("</tr>\r\n")
f.write("<tr>")
f.write("<td>Client</td>")
f.write("<td>" + str(count["client"]) + "</td>")
f.write("</tr>\r\n")
f.write("<tr>")
f.write("<td>Server</td>")
f.write("<td>" + str(count["server"]) + "</td>")
f.write("</tr>\r\n")
f.write("</table>\r\n\r\n")
f.write("## Individual Mods\r\n")
f.write("<table>")
f.write("\r\n<tr>")
f.write("<th>Name</th>")
f.write("<th>Side</th>")
f.write("<th>Link</th>")
f.write("</tr>\r\n")
for mod in mods:
data = mods[mod]
f.write("\r\n<tr>")
f.write("<td>" + mod + "</td>")
f.write("<td>" + data["side"] + "</td>")
if data["url"] != "":
f.write("<td><a href=\"" + data["url"] + "\">" + data["site"] + "</a></td>")
else:
f.write("<td>N/A</td>")
f.write("\r\n</tr>")
f.write("\r\n</table>")
with open("wiki/Licenses.md", "w") as f:
for mod in mods:
data = mods[mod]
f.write("## " + mod + "\r\n")
f.write("<b>")
if data["license"]["url"] != None:
f.write("<a href=\"" + data["license"]["url"] + "\">" + data["license"] + "")
else:
f.write(data["license"]["name"])
f.write("</b>\r\n")