forked from PolyMC/meta-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateLiteloader.py
executable file
·42 lines (29 loc) · 1.1 KB
/
updateLiteloader.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
import json
import os
import requests
from cachecontrol import CacheControl
from cachecontrol.caches import FileCache
from meta.common import upstream_path, ensure_upstream_dir
from meta.common.liteloader import VERSIONS_FILE, BASE_DIR
from meta.model.liteloader import LiteloaderIndex
UPSTREAM_DIR = upstream_path()
ensure_upstream_dir(BASE_DIR)
forever_cache = FileCache('caches/http_cache', forever=True)
sess = CacheControl(requests.Session(), forever_cache)
def main():
# get the remote version list
r = sess.get('http://dl.liteloader.com/versions/versions.json')
r.raise_for_status()
# make sure it's JSON
main_json = r.json()
# make sure we understand the schema
remote_versions = LiteloaderIndex.parse_obj(main_json)
parsed = remote_versions.json()
original = json.dumps(main_json, sort_keys=True, indent=4)
assert parsed == original
print("Successfully parsed index")
print(f"Last updated {remote_versions.meta.updated}")
# save the json it to file
remote_versions.write(os.path.join(UPSTREAM_DIR, VERSIONS_FILE))
if __name__ == '__main__':
main()