From d4357d5d6b26068f092c07edca6902401680e0d0 Mon Sep 17 00:00:00 2001 From: ferricles Date: Sun, 12 Jun 2022 20:54:53 -0700 Subject: [PATCH] merge conflicts + first part of refactor --- js/builder_graph.js | 23 +++++++++++++++++++++++ py_script/ci_parse.py | 2 ++ py_script/ci_scrape.py | 2 ++ py_script/clean_json.py | 13 +++++++++++++ py_script/compress_json.py | 19 ++++++++++++------- py_script/dump.py | 22 ---------------------- py_script/get.py | 33 +++++++++++++++++++++++++++++++++ py_script/image_get.py | 4 ++++ 8 files changed, 89 insertions(+), 29 deletions(-) create mode 100644 js/builder_graph.js create mode 100644 py_script/clean_json.py delete mode 100644 py_script/dump.py create mode 100644 py_script/get.py diff --git a/js/builder_graph.js b/js/builder_graph.js new file mode 100644 index 0000000..34e6f9b --- /dev/null +++ b/js/builder_graph.js @@ -0,0 +1,23 @@ + + +let item_nodes = []; + +document.addEventListener('DOMContentLoaded', function() { + for (const [eq, none_item] of zip(equipment_fields, none_items)) { + let input_field = document.getElementById(eq+"-choice"); + let item_image = document.getElementById(eq+"-img"); + + // let item_dropdown + + let item_input = new ItemInputNode(eq+'-input', input_field, none_item); + item_nodes.push(item_input); + new ItemInputDisplayNode(eq+'-display', input_field, item_image).link_to(item_input); + new PrintNode(eq+'-debug').link_to(item_input); + //document.querySelector("#"+eq+"-tooltip").setAttribute("onclick", "collapse_element('#"+ eq +"-tooltip');"); //toggle_plus_minus('" + eq + "-pm'); + + } + let weapon_image = document.getElementById("weapon-img"); + new WeaponDisplayNode('weapon-type', weapon_image).link_to(item_nodes[8]); + console.log("Set up graph"); + +}); diff --git a/py_script/ci_parse.py b/py_script/ci_parse.py index fc1772a..6318069 100644 --- a/py_script/ci_parse.py +++ b/py_script/ci_parse.py @@ -1,3 +1,5 @@ +#parses all CI and creates a json file with all of them + import os import re diff --git a/py_script/ci_scrape.py b/py_script/ci_scrape.py index a4ed7c6..92ab880 100644 --- a/py_script/ci_scrape.py +++ b/py_script/ci_scrape.py @@ -1,3 +1,5 @@ +#looks like something that hpp does with curl + import os with open("ci.txt.2") as infile: diff --git a/py_script/clean_json.py b/py_script/clean_json.py new file mode 100644 index 0000000..81276c3 --- /dev/null +++ b/py_script/clean_json.py @@ -0,0 +1,13 @@ +''' +A generic file used for turning a json into a compressed version of itself (minimal whitespaces). +Compressed files are useful for lowering the amount of data sent. + +Usage: python clean_json.py [infile rel path] [outfile rel path] +''' + +if __name__ == "__main__": + import sys + import json + infile = sys.argv[1] + outfile = sys.argv[2] + json.dump(json.load(open(infile)), open(outfile, "w"), indent = 2) diff --git a/py_script/compress_json.py b/py_script/compress_json.py index c4d4899..a826c36 100644 --- a/py_script/compress_json.py +++ b/py_script/compress_json.py @@ -1,8 +1,13 @@ -import sys -import json -infile = sys.argv[1] -outfile = sys.argv[2] -if len(sys.argv) > 3 and sys.argv[3] == "decompress": - json.dump(json.load(open(infile)), open(outfile, "w"), indent=4) -else: +''' +A generic file used for turning a json into a "clean" version of itself (human-friendly whitespace). +Clean files are useful for human reading and dev debugging. + +Usage: python compress_json.py [infile rel path] [outfile rel path] +''' + +if __name__ == "__main__": + import sys + import json + infile = sys.argv[1] + outfile = sys.argv[2] json.dump(json.load(open(infile)), open(outfile, "w")) diff --git a/py_script/dump.py b/py_script/dump.py deleted file mode 100644 index d649c7e..0000000 --- a/py_script/dump.py +++ /dev/null @@ -1,22 +0,0 @@ -import requests -import json -import numpy as np - -response = requests.get("https://api.wynncraft.com/public_api.php?action=itemDB&category=all") - -with open("dump.json", "w") as outfile: - outfile.write(json.dumps(response.json())) - -arr = np.array([]) -for i in range(4): - response = requests.get("https://api.wynncraft.com/v2/ingredient/search/tier/" + str(i)) - arr = np.append(arr, np.array(response.json()['data'])) - -with open("../ingreds.json", "w") as outfile: - outfile.write(json.dumps(list(arr))) - -with open("../ingreds_compress.json", "w") as outfile: - outfile.write(json.dumps(list(arr))) - -with open("../ingreds_clean.json", "w") as outfile: - json.dump(list(arr), outfile, indent = 2) #needs further cleaning diff --git a/py_script/get.py b/py_script/get.py new file mode 100644 index 0000000..ae5ba2b --- /dev/null +++ b/py_script/get.py @@ -0,0 +1,33 @@ +""" +Used to GET data from the Wynncraft API. Has shorthand options and allows +for requesting from a specific url. + +Usage: python get.py [url or command] [outfile rel path] + +Relevant page: https://docs.wynncraft.com/ +""" + +if __name__ == "__main__": + import requests + import json + import numpy as np + import sys + + #req can either be a link to an API page OR a preset default + req = sys.argv[1] + outfile = sys.argv[2] + response = {} #default to empty file output + + if req.lower() is "items": + response = requests.get("https://api.wynncraft.com/public_api.php?action=itemDB&category=all") + elif req.lower() is "ings": + response = requests.get("https://api.wynncraft.com/v2/ingredient/list") + elif req.lower() is "recipes": + response = requests.get("https://api.wynncraft.com/v2/recipe/list") + else: + response = requests.get(req) + + with open("dump.json", "w") as outfile: + outfile.write(json.dumps(response.json())) + + json.dump(response.json(), open(outfile, "w")) \ No newline at end of file diff --git a/py_script/image_get.py b/py_script/image_get.py index ebe22a3..9e3eced 100644 --- a/py_script/image_get.py +++ b/py_script/image_get.py @@ -1,3 +1,7 @@ +""" +Used for grabbing image files at some point. Not used recently. +""" + import os import json