-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
111 lines (91 loc) · 3.58 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from flask import Flask, render_template, redirect, url_for
from redis import Redis, RedisError
import os
import socket
import logging
from probemaker import Hero
from flask import request
if "settings.py" in os.listdir():
from settings import *
else:
# fallback if no custom settings are provided
from settings_template import *
# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)
logger = logging.getLogger("Basic Logger")
# Create Hero objects
hfiles = dict() # Dict for heros' .json files
group = dict() # Dict to collect all Hero objects
names = list() # List to collect all names of heros in group
# Create total path to hero files
for hero in heros:
hfiles[hero] = (data_folder / hero).resolve()
for h in hfiles:
Digga = Hero(hfiles[h], logger, show_values)
names.append(Digga.name)
group[Digga.name] = Digga
logger.info(f'{Digga.name} loaded')
heroes = group
possible_probes = []
for h in group.values():
possible_probes += h.possible_probes
actions = list(set(possible_probes))
actions.sort()
@app.route('/', methods=["GET", "POST"])
def index():
if request.method == 'POST':
print("getting here...")
print(request.form)
hero = request.form['hero_name']
talent = request.form['action_name']
modifier = int(request.form['modifier'])
hero_instance = group[hero]
passed, meister, mega_meister, patz, mega_patz = hero_instance.perform_action(user_action=talent, modifier=modifier)
rolls = hero_instance.rolls
print(f"Hero {hero} performing probe on talent {talent}.")
print(heroes)
return render_template('index.html', modifier=modifier, hero=hero, talent=talent, passed=passed, heroes=heroes, actions=actions, rolls=rolls, meister=meister, mega_meister=mega_meister, patz=patz, mega_patz=mega_patz)
#form = ActionEnteringForm()
#if form.validate_on_submit():
# Check the password and log the user in
# [...]
#return redirect(url_for('hello'))
#print(request.form['hero_name'])
return render_template('index.html', heroes=heroes, actions=actions)
@app.route("/hello")
def hello():
try:
visits = redis.incr("counter")
except RedisError:
visits = "<i>cannot connect to Redis, counter disabled</i>"
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Visits:</b> {visits}"
logging.basicConfig(filename='probe.log',
# encoding='utf-8',
format='%(asctime)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S;', level=logging.DEBUG)
logger = logging.getLogger("Basic Logger")
logger.info('Probemaker started')
if False:
hfiles = dict() # Dict for heros' .json files
group = dict() # Dict to collect all Hero objects
names = list() # List to collect all names of heros in group
# Create total path to hero files
for hero in heros:
hfiles[hero] = (data_folder / hero).resolve()
if debug:
print(heros)
print("Data folder", data_folder)
print(hfiles)
# Create Hero objects
for h in hfiles:
Digga = Hero(hfiles[h], logger, show_values)
names.append(Digga.name)
group[Digga.name] = Digga
logger.info(f'{Digga.name} loaded')
run(group)
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)