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