This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
executable file
·77 lines (55 loc) · 2.3 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""This is the module for the main flask app."""
import os
from flask import Flask, render_template, url_for, redirect, json, jsonify, request, abort
from flask_pymongo import PyMongo
from werkzeug.routing import BaseConverter
from bson import json_util
import shadowcraft_ui
from shadowcraft_ui import backend
os.environ['PYTHONIOENCODING'] = 'utf-8'
APP = Flask('shadowcraft_ui')
APP.config['SECRET_KEY'] = 'shhhhhhhh!'
APP.config['MONGO_DBNAME'] = 'roguesim_python'
# Have to do this so that the request object sent to the /engine endpoint doesn't
# overrun the limit
APP.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024
mongo = PyMongo(APP)
class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
APP.url_map.converters['regex'] = RegexConverter
# Main route for the application. This will call into react and let Router handle
# the actual render of either the front page or a character page depending on the
# path.
@APP.route('/', defaults={'path': ''})
@APP.route('/<path:path>')
def main(path):
return render_template('index.html')
# Engine endpoints. /engine is a call to get DPS data. /settings gives back the
# default settings configuration.
@APP.route('/engine', methods=['POST'])
def engine():
output = backend.get_engine_output(mongo.db, request.get_json())
return jsonify(output)
@APP.route('/settings')
def settings():
settings_data = backend.get_settings()
return jsonify(settings_data)
# Endpoint for requesting a new debug SHA based on from character data.
@APP.route('/get_sha', methods=['POST'])
def get_sha():
return jsonify(shadowcraft_ui.get_debug_sha(mongo, request.get_json()))
@APP.route('/get_character_data')
def get_character_data():
region = request.args.get('region')
realm = request.args.get('realm')
name = request.args.get('name')
sha = request.args.get('sha')
data = shadowcraft_ui.get_character_data(mongo, region, realm, name, sha)
if 'http_status' in data:
return json_util.dumps(data), data['http_status'], {'Content-Type': 'application/json'}
else:
return json_util.dumps(data), 200, {'Content-Type': 'application/json'}
if __name__ == '__main__':
APP.run(debug=True, host='0.0.0.0', port=5000, threaded=True)