updateLiteloader.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import json
  2. import os
  3. import requests
  4. from cachecontrol import CacheControl
  5. from cachecontrol.caches import FileCache
  6. from meta.common import upstream_path, ensure_upstream_dir
  7. from meta.common.liteloader import VERSIONS_FILE, BASE_DIR
  8. from meta.model.liteloader import LiteloaderIndex
  9. UPSTREAM_DIR = upstream_path()
  10. ensure_upstream_dir(BASE_DIR)
  11. forever_cache = FileCache('caches/http_cache', forever=True)
  12. sess = CacheControl(requests.Session(), forever_cache)
  13. def main():
  14. # get the remote version list
  15. r = sess.get('http://dl.liteloader.com/versions/versions.json')
  16. r.raise_for_status()
  17. # make sure it's JSON
  18. main_json = r.json()
  19. # make sure we understand the schema
  20. remote_versions = LiteloaderIndex.parse_obj(main_json)
  21. parsed = remote_versions.json()
  22. original = json.dumps(main_json, sort_keys=True, indent=4)
  23. assert parsed == original
  24. print("Successfully parsed index")
  25. print(f"Last updated {remote_versions.meta.updated}")
  26. # save the json it to file
  27. remote_versions.write(os.path.join(UPSTREAM_DIR, VERSIONS_FILE))
  28. if __name__ == '__main__':
  29. main()