-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (59 loc) · 1.89 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
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request, redirect, url_for
from methods import result
import json
import random
import io
app = Flask(__name__)
encoding = io.open('./static/data.json', 'r')
file_content = encoding.read()
file_content = file_content.replace('Ã¥', 'å')
file_content = file_content.replace('ø', 'ø')
file_content = file_content.replace('Ø', 'Ø')
file_content = file_content.replace('æ', 'æ')
j = json.loads(file_content)
# Variables
answers = []
winners_alt = []
g = 0
@app.route('/')
@app.route('/<page>')
def index(page=None):
if page == None:
reset()
return render_template('index.html')
else:
return render_template('slides.html', question=j['spm'][0]['q'], varBtn="Neste Spørsmål")
@app.route('/next', methods=['GET', 'POST'])
def next():
global g
global answers
global winners_alt
answers.append(request.form['input'])
if request.form['sender'] == 'NEXT':
if g == len(j['spm'])-1:
result(answers, j, winners_alt)
return render_template('done.html', rankings=winners_alt)
else:
g += 1
if request.method == 'POST':
if g == len(j['spm'])-2:
return render_template('slides.html', question=j['spm'][g]['q'], varBtn = "Fullfør")
else:
return render_template('slides.html', question=j['spm'][g]['q'], varBtn = "Neste Spørsmål")
@app.route('/restart', methods=['GET', 'POST'])
def restart():
reset()
# Returning user to the startpage
return render_template('index.html')
def reset():
# Resetting all variables
global g
global answers
global winners_alt
g = 0
del answers[:]
del winners_alt[:]
if __name__ == "__main__":
app.debug = True
app.run()