Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import os
- import wget
- import zipfile
- def separator():
- print(f"{'_' * 50}")
- home_url = "https://mods.vintagestory.at"
- mod_api = "http://mods.vintagestory.at/api/mod"
- """
- mod_api = "http://mods.vintagestory.at/api/mods"
- def fetch_data():
- #get full list of mods from databas
- res = requests.get(mod_api, headers={"Accept": "application/json"})
- if res.status_code == 200:
- try:
- sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
- data = res.json()
- # with open("mods.json", "w", encoding="utf-8") as md:
- # md.write(json.dumps(data, indent=4))
- return data
- except Exception as e:
- print(e)
- data = fetch_data()
- mod_data = data["mods"]
- mod_names = []
- for x in mod_data:
- mod_names.append(x["name"])
- """
- curr_path = os.path.dirname(os.path.abspath(__file__))
- if not os.path.isfile(".\\modsdir.txt"):
- f = open(".\\modsdir.txt", "w+")
- mods_dir = input("What is your mod directory?")
- f.write(mods_dir)
- f.close
- f = open(".\\modsdir.txt", "r")
- if f.read() == "":
- f.close()
- f = open(".\\modsdir.txt", "w")
- mods_dir = input("What is your mod directory?")
- f.write(mods_dir)
- f.close()
- f.close()
- f = open(".\\modsdir.txt", "r")
- modpath = f.read()
- f.close()
- path_out = ".\\output"
- if not os.path.isdir(path_out):
- os.mkdir(path_out)
- print("Creating output directory")
- modlist = os.listdir(modpath)
- mod_info_list = []
- print("Mods in your folder: \n")
- for mod in modlist:
- # Get modinfo.json data inside local mod-zipfile
- if mod[-4:-1] + mod[-1] == ".zip":
- get_zip = zipfile.ZipFile(mod, mode="r")
- with get_zip.open("modinfo.json", mode="r") as mod_info:
- mod_info_json = json.loads(str(mod_info.read().decode("utf-8")))
- mod_info_list.append(mod_info_json)
- print(mod_info_json["name"])
- separator()
- print("\nChecking for updates...\n")
- for mod in mod_info_list:
- api_req = mod_api + "/" + str(mod["modid"])
- # Get new mod info data from database to check version
- mod_res = requests.get(api_req, headers={"Accept": "application/json"})
- res_modinfo = mod_res.json()["mod"]
- releases = res_modinfo["releases"][0]
- if releases["modversion"] != mod["version"]:
- separator()
- print("\n" + mod["name"] + " has a newer version!")
- print("Downloading from:")
- file_id = releases["fileid"]
- downlink = home_url + "/download?fileid=" + str(file_id)
- print(downlink)
- response = wget.download(downlink, out=path_out)
- print("\nDone! Check output folder\n")
- separator()
- else:
- print(mod["name"] + " is the latest!")
- separator()
- input("\n\nDownload complete, press Enter to exit!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement