-
Notifications
You must be signed in to change notification settings - Fork 0
/
CloudP1.py
81 lines (67 loc) · 1.96 KB
/
CloudP1.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
import connections
import re
from flask import Flask, render_template, request
import time
print(time)
app = Flask(__name__)
c, conn = connections.connection()
halls = []
@app.route('/')
def hello_world():
c.execute("SELECT hall_name FROM hall")
cc = c.fetchall()
hall_names = []
for c1 in cc:
hall_names.append(''.join(c1))
print(''.join(c1))
print(hall_names)
global halls
halls = hall_names
return render_template('home.html', hall_names=halls)
class event:
def __init__(self, name, location, time):
self.name = name
self.location = location
self.time = time
ee_dict = {}
@app.route('/<hall_name>', methods=['GET', 'POST'])
def hall_lookup(hall_name):
global halls
hall_name = hall_name
events = []
print("hall_name = ")
print(hall_name)
if request.method == "POST":
c.execute("SELECT event_name, location, event_time FROM events WHERE hall_name=(%s)", (hall_name,))
events = c.fetchall()
print(events[0])
print(type(events))
x = {"one": 1, "two": 2, "three": 3}
print(x["one"])
ee = {}
for e in events:
print("in for loop")
ob = event(re.sub('[^A-Za-z ]+', '', e[0]), re.sub('[^A-Za-z0-9: ]+', '', e[1]), re.sub('[^A-Za-z0-9: ]+', '', e[2]))
details = [ob.location, ob.time]
print(details)
ee[ob.name] = details
print(ee)
global ee_dict
ee_dict = ee
return render_template('home.html', events=ee, hall_names=halls, hall_name=hall_name)
@app.route('/search/', methods=["GET", "POST"])
def search():
searchfor = request.form['searchfor']
print(searchfor)
result = []
print(ee_dict)
for k in ee_dict:
for v in ee_dict[k]:
print(v)
if searchfor in v:
print(v)
result.append(v)
print(result)
return render_template('home.html', hall_names=halls, search_results=result)
if __name__ == '__main__':
app.run()