This repository was archived by the owner on Sep 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
45 lines (36 loc) · 1.55 KB
/
application.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
from flask import Flask, render_template, url_for, redirect
import pickle
# example dictionary of event data for testing
# from testData import data
# EB looks for an 'application' callable by default.
application = Flask(__name__)
# redirect to Tree-Plenish site if no school input
@application.route('/')
def index():
return redirect('https://www.tree-plenish.org/')
@application.route('/<string:schoolName>')
def schoolPage(schoolName):
# Use schoolName or some other event identifier to get event data
# Try getting school info
try:
# if schoolName != "Timber Woods High School" and schoolName != "Timber Woods High School2": # just for demo
# raise Exception
# get school data from dict from pickle file
with open('eventDataDict.pkl', 'rb') as handle:
eventData = pickle.load(handle)[schoolName]
# eventData = data[schoolName]
print(eventData)
# schoolName = "Timber Woods High School"
# Then send in as event to webpage
return render_template('index.html', event=eventData, school=schoolName)
except Exception as e:
print(e)
# redirect to error page if any error with loading data or school not found
print('School not found')
return render_template('error.html', school=schoolName)
# run the app.
if __name__ == "__main__":
# Setting debug to True enables debug output. This line should be
# removed before deploying a production app.
# application.debug = True
application.run()