-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
129 lines (113 loc) · 4.64 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
from flask import Flask,render_template
# this makes app an instance of the Flask class
# and it passed the special variable __name__ into
# the constructor
from twitter import *
from wordCount import *
import plotly.plotly as py
from plotly.graph_objs import *
import urllib
def topTrend(loc):
trends = trendsByLocation(loc)
query = trends[1]
print trends[0]
print trends[1]
tweetss = tweets(query, count=10000)
wCount = wordCount(tweetss)
lCount = locCount(tweetss)
listResults = dictListRev(wCount)[0:10]
print listResults
#Most commmon words
x = [v for k, v in listResults[1:]]
y = [k for k, v in listResults[1:]]
repTweet = closeMatch(listResults, tweetss)
sortLoc = sorted(lCount, key=lambda tup: tup[0], reverse=True)[:10]
print sortLoc
data = Data([
Bar(
x=x,
y=y,
name='',
marker=Marker(
color='rgb(0, 149 ,255)'
))
])
layout = Layout(
title=listResults[0][1],
xaxis=XAxis(
title='Hashtags and Words',
titlefont=Font(
size=16,
color='rgb(107, 107, 107)'
),
tickfont=Font(
size=14,
color='rgb(107, 107, 107)'
)
),
yaxis=YAxis(
title='Number of Occurrences',
titlefont=Font(
size=16,
color='rgb(107, 107, 107)'
),
tickfont=Font(
size=14,
color='rgb(107, 107, 107)'
)
)
)
fig = Figure(data=data, layout=layout)
plot_url0 = py.plot(fig, filename="Common Words: " + str(listResults[0][1]))
print plot_url0
#Locations of common tweets
xb = [v for k, v in sortLoc]
yb = [k for k, v in sortLoc]
datab = Data([
Bar(
x=xb,
y=yb,
name='',
marker=Marker(
color='rgb(0, 149 ,255)'
))
])
layoutb = Layout(
title=listResults[0][1],
xaxis=XAxis(
title='Locations',
titlefont=Font(
size=16,
color='rgb(107, 107, 107)'
),
tickfont=Font(
size=14,
color='rgb(107, 107, 107)'
)
),
yaxis=YAxis(
title='Number of Occurrences',
titlefont=Font(
size=16,
color='rgb(107, 107, 107)'
),
tickfont=Font(
size=14,
color='rgb(107, 107, 107)'
)
))
figb = Figure(data=datab, layout=layoutb)
plot_url1 = py.plot(figb, filename="Locations: " + str(listResults[0][1]))
print plot_url1
return (listResults[0][1], plot_url0, plot_url1, repTweet)
app = Flask(__name__)
#@app.route("/home")
@app.route("/<loc>")
def home(loc):
ttrend, url0, url1, repTweet = topTrend(loc)
return render_template("display.html", place=urllib.unquote_plus(loc), trend=ttrend, ploturl0=url0, ploturl1=url1, topTweet = repTweet)
# return render_template("results.html", trends=trends())
if __name__=="__main__":
app.debug=True
app.run()
#app.run(host="0.0.0.0",port=8888)