-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask-server.py
107 lines (84 loc) · 2.5 KB
/
flask-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
104
105
106
107
import timetable
import exTime
import os
import datetime
import requests
import os
import time
import sys
import cgi
from flask import Flask
from flask import request
from flask import render_template
app = Flask(__name__)
# Init timetable in memory
htmlFile = ''
lastUpdate = ''
version = 'v1.1.0'
@app.route('/')
def displayVenues():
fullTime = datetime.datetime.now().strftime('%A %H:%M:%S')
# Get time variables
day = datetime.datetime.now().strftime('%A')
timeA = datetime.datetime.now().strftime('%H:%M')
timeB = exTime.convertTimeStringToMinutes(timeA)
timeB = timeB + 60
timeB = exTime.convertMinutesToTimeString(timeB)
timeTableObject = timetable.getTimetableFromHTML(htmlFile)
emptyA = timetable.getEmptyVenuesFromFullTimetable(day, timeA, timeTableObject)
emptyB = timetable.getEmptyVenuesFromFullTimetable(day, timeB, timeTableObject)
emptyA.sort()
emptyB.sort()
emptyC = getDualColumnList(emptyA, emptyB)
return render_template('index.html', version=version, dualColumnList=emptyC, timeA=timeA, timeB=timeB, fullTime=fullTime, lastUpdate=lastUpdate), 200
@app.route('/update')
def updateTimetableInMemory_trigger():
updateTimetableInMemory()
return render_template('update.html'), 200
def updateTimetableInMemory():
global htmlFile
global lastUpdate
htmlRequest = requests.get('http://upnet.up.ac.za/tt/hatfield_timetable.html')
htmlFile = htmlRequest.text
lastUpdate = datetime.datetime.now().strftime('%A %H:%M:%S')
# NOTE
updateTimetableInMemory()
@app.route('/flask_log')
def displayFlaskLog():
f = open('/mnt/dalla-hdd/dalla/emptiness/flask-server.log', 'r')
data = f.read()
data = cgi.escape(data)
f.close()
return '<pre>' + data + '</pre>', 200
def getDualColumnList(listA, listB):
listC = []
# if len(listA) == 0:
# for i in range(0, len(listB)):
# listC.append(' ')
# listC.append(listB[i])
# return listC
#
# if len(listB) == 0:
# for i in range(0, len(listA)):
# listC.append(listA[i])
# listC.append(' ')
# return listC
if len(listA) > len(listB):
# Populate until B runs out
for i in range(0, len(listB)):
listC.append(listA[i])
listC.append(listB[i])
# B is now exhausted, continue with A
for i in range(len(listB), len(listA)):
listC.append(listA[i])
listC.append(' ')
else:
# Populate until A runs out
for i in range(0, len(listA)):
listC.append(listA[i])
listC.append(listB[i])
# A is now exhausted, continue with B
for i in range(len(listA), len(listB)):
listC.append(' ')
listC.append(listB[i])
return listC