-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
132 lines (120 loc) · 4.52 KB
/
app.py
File metadata and controls
132 lines (120 loc) · 4.52 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from flask import Flask, render_template, request, session, redirect, url_for, Response, jsonify
import util
import hashlib
import random
app = Flask(__name__)
app.secret_key = "nothing"
util.create()
@app.route('/')
@app.route('/index')
def index():
return render_template("index.html")
@app.route('/restaurants', methods=["GET","POST"])
def restaurants():
if request.method == "POST":
form = request.form
details = form['details']
session['details'] = details
details = [c.strip() for c in details.strip().strip(',').split(';')]
#address radius ratings categories
address = details[0]
radius = int(details[1]) * 1609
rating = details[2]
types = [d.strip() for d in details[3].split(',')]
session['setrad'] = details[1]
session['setrating'] = rating
session['addr'] = address
if 'types' in session:
session['types'] += types
else:
session['types'] = types
results = util.filter(address,radius,types,rating)
cats = util.getTypes(address,radius)
i = 0
while i < len(cats):
if cats[i] in session['types']:
cats.pop(i)
else:
i += 1
for result in results:
result['category'] = catformat(result['category'])
return render_template('restaurants.html', results=results,categories=cats)
return redirect('/index')
def catformat(cats):
dog = ""
for cat in cats:
dog += cat + ","
return dog[:-1]
@app.route('/results')
def results():
args = request.args
addr = args.get('addr')
result = util.getTypes(addr)
return jsonify(result=result)
@app.route('/history')
@app.route('/history/<location>/<restaurant>/<category>/<rating>', methods=['GET','POST'])
def history(location="",restaurant="",category="",rating=0):
if location=="":
return redirect('/index')
# if request.method == "POST":
# form = request.form
# rating = form['rating']
# session['rating'] = rating
# util.setrating(session['user'], rating, location, restaurant, category)
#rating = util.getrating(location)
session['rating'] = rating
# if len(rating) > 0:
# rating = reduce(lambda x, y: x+y, rating)/len(rating)
# rating = int(rating * 10) / 10.
#else:
damn = util.filter(session['addr'], 10000)
damn = damn[random.randrange(len(damn))]
print damn
damn = '/history/%s,%s/%s/%s/%s'%(damn['location'][0],damn['location'][1],damn['name'],catformat(damn['category']),damn['rating'])
return render_template('rating.html',restaurant=restaurant,location=location.split(','),category=category.split(','), randomurl=damn)
#return render_template('rating.html',rating = rating,restaurant=restaurant,location=location.split(','),category=category.split(','))
@app.route('/login', methods = ["GET","POST"] )
def login():
if request.method == "POST":
form = request.form
username = form.get('user')
password = form.get('pwd')
auth = util.authenticate(username, password)
if auth == "":
session['user'] = username
session['userhash'] = m = hashlib.sha224(username).hexdigest()
return redirect('/')
else:
return render_template('login.html', error=auth)
return render_template('login.html')
@app.route('/register', methods=["GET","POST"])
def register():
if request.method == "POST":
form = request.form
user = form.get('user')
pwd = form.get('pwd')
pwdtwo = form.get('pwd2')
if pwd != pwdtwo:
return render_template('register.html',err="Passwords Do Not Match")
elif len(pwd) < 6:
return render_template('register.html', err="Password must be at least 6 characters")
elif not pwd.isalnum():
return render_template('register.html', err="Password cannot contain special characters")
elif not util.newUser(user,pwd):
return render_template('register.html', err="Username Taken")
else:
session['user'] = user
return redirect('/index')
return render_template('register.html')
@app.route("/address")
def address():
return render_template("/address.html")
@app.route("/about")
def about():
about = ""
with open("README.txt") as file:
about = file.read()
return render_template("/about.html",about=about)
if __name__ == '__main__':
app.debug = True
app.run(host = "0.0.0.0", port = 8080)