-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathapp.py
151 lines (125 loc) · 3.04 KB
/
app.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from modules.analysis import isNBA
from modules.scraper import get_playoff_bracket, get_standings
from modules.transformer import create_html_bracket
from modules.query import Query
from data.text_data import unsure, non_nba
from flask import Flask, render_template, request, jsonify, redirect
app = Flask(__name__)
"""
Function to handle routing to home page.
Parameters
----------
n/a
Returns
-------
HTML file
Rendering of HTML template for home page.
"""
@app.route("/")
def home():
return render_template("home.html")
@app.route("/home")
def home2():
return render_template("home.html")
"""
Function to handle routing to chatbox page.
Parameters
----------
n/a
Returns
-------
HTML file
Rendering of HTML template for chatbox page
"""
@app.route("/chat")
def chat():
return render_template("chat.html")
"""
Function to render blogs page.
Parameters
----------
n/a
Returns
-------
HTML file
Rendering of HTML template for blog page
"""
@app.route("/blog")
def blog():
return render_template("blogs.html")
"""
Function to handle routing to authors page.
Parameters
----------
n/a
Returns
-------
HTML file
Rendering of HTML template for authors page
"""
@app.route("/authors")
def authors():
return render_template("authors.html")
"""
Function to handle routing to predictions page.
Parameters
----------
n/a
Returns
-------
HTML file
Rendering of HTML template for predictions page
"""
@app.route("/predictions")
def predictions():
bracket = get_playoff_bracket()
bracket = create_html_bracket(bracket)
west_standings = get_standings("west")
east_standings = get_standings("east")
return render_template("predictions.html", bracket=bracket, west_standings=west_standings, east_standings=east_standings)
"""
Function to download requested blog for user.
Parameters
----------
n/a
Returns
-------
HTML file
Rendering of HTML template for blog page.
"""
@app.route("/download/<string:id>", methods=['GET', 'POST'])
def download(id):
if id is None:
self.Error(400)
try:
blog_map ={
"1" : "https://drive.google.com/uc?export=download&id=13FmzW70fMMfTwrypxzJRG-J6woty8ePz", # Dog pic
"2" : "https://drive.google.com/uc?export=download&id=13FmzW70fMMfTwrypxzJRG-J6woty8ePz", # Dog pic
"3" : "https://drive.google.com/uc?export=download&id=13FmzW70fMMfTwrypxzJRG-J6woty8ePz" # Dog pic
}
return redirect(blog_map[id])
except Exception as e:
self.log.exception(e)
self.Error(400)
"""
Function to handle POST request from user
with embedded message. The message is then
passed to the chatbot and the response is returned
to user.
Parameters
----------
request : json
The POST request sent from user sending a message
Returns
-------
Bot response : json
The chatbot response to user message
"""
@app.route("/bot-msg", methods=['POST'])
def get_bot_response():
usr_msg = request.form['msg']
handler = Query(usr_msg)
response = handler.process()
return jsonify(response)
if __name__ == "__main__":
app.run()