-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
103 lines (80 loc) · 2.89 KB
/
server.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
#!/usr/bin/python3
from flask import Flask, request, jsonify, send_file
import random
app = Flask(__name__)
help_queue = []
checkoff_queue = []
@app.route('/')
def index():
index_file = 'www/index.html'
return send_file(index_file)
@app.route('/scripts.js')
def js():
js_file = 'www/scripts.js'
return send_file(js_file)
@app.route('/queue/help', methods=['GET', 'POST'])
def help_queue_manager():
msg = ''
if request.method == 'POST':
first_name = request.values.get('first_name')
last_name = request.values.get('last_name')
kerberos = request.values.get('kerberos')
remove = True if request.values.get('remove') == 'true' else False
if kerberos and first_name and last_name:
entry = (first_name, last_name, kerberos)
if remove and entry in help_queue:
help_queue.remove(entry)
msg = 'removed from queue'
elif entry not in help_queue:
help_queue.append(entry)
msg = 'added to queue'
else:
msg = 'already added to queue'
return jsonify({'message': msg})
else:
msg = 'missing queue data'
else:
return jsonify({'help_queue': help_queue, 'message':msg})
return jsonify({'error_code': 400, 'message': msg})
@app.route('/queue/checkoff', methods=['GET', 'POST'])
def checkoff_queue_manager():
msg = ''
if request.method == 'POST':
first_name = request.values.get('first_name')
last_name = request.values.get('last_name')
kerberos = request.values.get('kerberos')
remove = True if request.values.get('remove') == 'true' else False
if kerberos and first_name and last_name:
entry = (first_name, last_name, kerberos)
if remove and entry in checkoff_queue:
checkoff_queue.remove(entry)
msg = 'removed from queue'
elif entry not in checkoff_queue:
checkoff_queue.append(entry)
msg = 'added to queue'
else:
msg = 'already added to queue'
return jsonify({'message': msg})
else:
msg = 'missing queue data'
else:
return jsonify({'checkoff_queue': checkoff_queue, 'message': msg})
return jsonify({'error_code': 400, 'message': msg})
@app.route('/partners', methods=['GET'])
def get_random_pair():
with open('roster.txt') as f:
roster = f.read()
people = roster.split('\n')
names = []
for p in people:
names.append(p.split(',')[0].strip())
if len(names) % 2 != 0:
names.append('')
random.shuffle(names)
pairs = ''
for i in range(0, len(names), 2):
pairs += "<h1>" + str(i//2+1) + ") " + names[i] + ", " + names[i+1] + "</h1>"
return pairs
if __name__ == "__main__":
port = 5000
app.run(host='0.0.0.0', port=port)