From 1fbc508b4bd15c71e7a02aab393cacd1bdfa1da8 Mon Sep 17 00:00:00 2001 From: Stefan Regnery Date: Mon, 21 Jan 2019 21:11:01 +0100 Subject: [PATCH] update updater to python3 add display dps.reports wsgi app --- arc-dps-updater/config.json | 18 +++---- arc-dps-updater/update.py | 61 ------------------------ arc-dps-updater/updater.py | 65 ++++++++++++++++++++++++++ display-all-reports/display-reports.py | 49 +++++++++++++++++++ 4 files changed, 123 insertions(+), 70 deletions(-) delete mode 100644 arc-dps-updater/update.py create mode 100644 arc-dps-updater/updater.py create mode 100644 display-all-reports/display-reports.py diff --git a/arc-dps-updater/config.json b/arc-dps-updater/config.json index ae1f9c5..5a931e0 100644 --- a/arc-dps-updater/config.json +++ b/arc-dps-updater/config.json @@ -1,11 +1,11 @@ { -arc_dps_buildtemplates: { -download_path: "https://www.deltaconnected.com/arcdps/x64/buildtemplates/d3d9_arcdps_buildtemplates.dll" -}, -arc_dps: { -current_version: "2b1dc4e1436ed6ffa55cc15f9351239a", -md5path: "https://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum", -download_path: "https://www.deltaconnected.com/arcdps/x64/d3d9.dll" -}, -guildwars2_path: "F:\Games\Guild Wars 2" + "arc_dps": { + "download_path": "https://www.deltaconnected.com/arcdps/x64/d3d9.dll", + "md5path": "https://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum", + "current_version": "13ebe41cf5592c7096a0c8d1b36ded35" + }, + "guildwars2_path": "C:\\Program Files\\Guild Wars 2", + "arc_dps_buildtemplates": { + "download_path": "https://www.deltaconnected.com/arcdps/x64/buildtemplates/d3d9_arcdps_buildtemplates.dll" + } } \ No newline at end of file diff --git a/arc-dps-updater/update.py b/arc-dps-updater/update.py deleted file mode 100644 index 330d0ed..0000000 --- a/arc-dps-updater/update.py +++ /dev/null @@ -1,61 +0,0 @@ -import shutil -import json -import os -import requests -import urllib3 -import urllib2 -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 = urllib2.urlopen(url, context=ctx) - f = open(file_name, 'wb') - meta = u.info() - file_size = int(meta.getheaders("Content-Length")[0]) - 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) - status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size) - status += chr(8) * (len(status) + 1) - print status, - - f.close() - - -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)) diff --git a/arc-dps-updater/updater.py b/arc-dps-updater/updater.py new file mode 100644 index 0000000..4b80ad8 --- /dev/null +++ b/arc-dps-updater/updater.py @@ -0,0 +1,65 @@ +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() diff --git a/display-all-reports/display-reports.py b/display-all-reports/display-reports.py new file mode 100644 index 0000000..1800707 --- /dev/null +++ b/display-all-reports/display-reports.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +import textwrap +import requests +from flask import Flask, Response, request + +app = Flask(__name__) + + +USER_TOKEN = '' + +def get_uploads(user_token, page=1): + return requests.get("https://dps.report/getUploads?userToken={}&page={}".format(user_token, page)).json() + + +@app.route("/") +def fetch_and_display_my_reports(): + if request.args.get('page', ''): + uploads = get_uploads(USER_TOKEN, request.args.get('page', '')) + else: + uploads = get_uploads(USER_TOKEN) +# print(uploads) + upload_links_html = "" + for upload in uploads['uploads']: + upload_links_html += ' {url}
\n'.format(url=upload['permalink']) + + older_reports = "
Older reports: " + if uploads['pages'] > 1: + for i in range(uploads['pages']): + if request.args.get('page', '') == str(i+1): + older_reports += ' {page_number} '.format(page_number=i+1) + else: + older_reports += ' {page_number} '.format(page_number=i+1) + + else: + older_reports = "" + response_text = textwrap.dedent('''\ + + + + lennys dps reports + + + {upload_links}{older_reports} + + '''.format(upload_links=upload_links_html, older_reports=older_reports)) + return Response(response_text, mimetype='text/html') + +def start(): + app = Flask(__name__)