This repository has been archived by the owner on Jun 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
59 lines (45 loc) · 1.48 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Built-ins
import json
import logging
# Project
from config import Config
from forms import ImportForm
from parse_stuff import parse
from table import generate_table
# Third-party
import pobapi
from flask import Flask, render_template
logger = logging.getLogger(__name__)
app = Flask(__name__)
app.config.from_object(Config)
with open("quest_data.json", "r") as f:
quest_data = json.load(f)
with open("skill_data.json", "r") as f:
skill_data = json.load(f)
@app.route("/", methods=["GET", "POST"])
def index():
form = ImportForm()
if form.validate_on_submit():
# Remove excessive whitespace from user input
import_code = form.import_code.data.strip()
return vendor(import_code)
return render_template("index.html", form=form)
@app.route("/about")
def about():
return render_template("about.html")
def vendor(import_code):
# Error handling on bad url or b64
try:
if import_code.startswith("https://pastebin.com/"):
build = pobapi.from_url(import_code)
else:
build = pobapi.from_import_code(import_code)
except ValueError:
form = ImportForm()
form["import_code"].errors = ["Not a valid pastebin.com URL or import code."]
return render_template("index.html", form=form)
store = parse(build, quest_data, skill_data)
tables = generate_table(store)
return render_template("vendor.html", tables=tables)
if __name__ == "__main__":
app.run(host="127.0.0.1", port=5000)