-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
49 lines (37 loc) · 1.37 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
from flask import Flask, render_template, abort
import sqlite3
import os
import unicodedata
app = Flask(__name__)
cities = ["Seattle", "Chicago", "New York"]
DB_PATH = os.path.join("./assets/", "summary.db")
@app.route('/')
def home():
return render_template("index.html", title="The AirBnB Review Summarizer")
@app.route('/city/<city>')
def city(city):
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute("SELECT city FROM hosts")
cities = []
for row in cursor.fetchall():
cities.append(row[0])
if city not in cities:
abort(404)
cursor.execute("SELECT words FROM topwords WHERE city = ?", (city,))
words = cursor.fetchone()[0]
cursor.execute("SELECT data FROM hosts WHERE city = ?", (city,))
hosts = cursor.fetchone()[0]
cursor.execute("SELECT topics FROM topics WHERE city = ?", (city,))
topics = cursor.fetchone()[0]
cursor.execute("SELECT places FROM places WHERE city = ?", (city,))
places = cursor.fetchone()[0]
cursor.execute("SELECT positive, negative, neutral FROM sentiment WHERE city = ?", (city,))
sentiments = cursor.fetchone()
cursor.close()
conn.close()
return render_template("city.html", title=city,
city=city, sentiments=sentiments, words=words,
hosts=hosts, topics=topics, places=places)
if __name__ == '__main__':
app.run(debug=False)