-
Notifications
You must be signed in to change notification settings - Fork 23
/
update_assets.py
81 lines (61 loc) · 2.08 KB
/
update_assets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import asyncclick as click
import orjson
from gtnh.defs import ModSource
from gtnh.modpack_manager import GTNHModpackManager
import httpx
def update_external_mods():
with open("gtnh-assets.json") as f:
blah = f.read()
assets = orjson.loads(blah)
for mod in assets["external_mods"]:
if mod.get("source", None) == "other":
continue
project = mod.get("project_id")
if not project:
continue
versions = mod.get("versions")
if not versions:
continue
for version in versions:
browser_download_url = version.get("browser_download_url")
if not browser_download_url:
continue
try:
file_no = int(browser_download_url.split("/")[-1])
except ValueError:
continue
version["curse_file"] = {"project_no": project, "file_no": file_no}
print(f"Added curse file for {project}: {browser_download_url}")
with open("gtnh-assets.json", "wb") as f:
f.write(orjson.dumps(assets))
return assets
@click.command()
async def update_to_mod():
async with httpx.AsyncClient(http2=True) as client:
m = GTNHModpackManager(client)
for mod in m.assets.github_mods:
if mod.name in ["DummyCore"]:
continue
m.assets.add_mod(mod)
for mod in m.assets.external_mods:
if m.assets.has_mod(mod.name):
print(f"Skipping duplicate external mod {mod.name}")
continue
mod.source = ModSource.curse
m.assets.add_mod(mod)
del m.assets.github_mods
del m.assets.external_mods
m.save_assets()
@click.command()
async def cleanup_maven_urls():
async with httpx.AsyncClient(http2=True) as client:
m = GTNHModpackManager(client)
for mod in m.assets.mods:
for v in mod.versions:
if v.maven_url and "github.com" in v.maven_url:
v.maven_url = None
m.save_assets()
if __name__ == "__main__":
# update_external_mods()
# m = update_to_mod()
cleanup_maven_urls()