guildwars-stuff/arc-dps-updater/updater.py
Stefan Regnery 1fbc508b4b update updater to python3
add display dps.reports wsgi app
2019-01-21 21:11:01 +01:00

66 lines
1.9 KiB
Python

import shutil
import json
import os
import requests
import urllib3
from urllib import request
import ssl
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
with open("config.json", mode="r") as config_file:
config = json.load(config_file)
def get_md5sum(md5_url):
r = requests.get(md5_url, verify=False, stream=True)
return str(r.text.split(" ")[0])
def download_file(url):
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
file_name = url.split('/')[-1]
u = request.urlopen(url)
f = open(file_name, 'wb')
file_size = int(u.getheader("Content-Length"))
print("Downloading: %s Bytes: %s" % (file_name, file_size))
file_size_dl = 0
block_sz = 8192
while True:
file_buffer = u.read(block_sz)
if not file_buffer:
break
file_size_dl += len(file_buffer)
f.write(file_buffer)
f.close()
def main():
global config_file
online_version = get_md5sum(config["arc_dps"]["md5path"])
arc_dps_url = config["arc_dps"]["download_path"]
buildtemplates_url = config["arc_dps_buildtemplates"]["download_path"]
if config["arc_dps"]["current_version"] != online_version:
arc_dps_file_name = arc_dps_url.rsplit('/', 1)[-1]
buildtemplates_file_name = buildtemplates_url.rsplit('/', 1)[-1]
download_file(arc_dps_url)
download_file(buildtemplates_url)
shutil.move(arc_dps_file_name, os.path.join(config["guildwars2_path"], "bin64", arc_dps_file_name))
shutil.move(buildtemplates_file_name,
os.path.join(config["guildwars2_path"], "bin64", buildtemplates_file_name))
config["arc_dps"]["current_version"] = online_version
with open("config.json", mode="w") as config_file:
config_file = (json.dump(config, config_file, indent=2))
if __name__ == "__main__":
main()