-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
executable file
·59 lines (54 loc) · 1.72 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
import os
from flask import Flask,render_template, request, jsonify
from tweetdump import *
from sentAnalysis import *
import json
app = Flask(__name__)
@app.route('/')
def hello():
# data = get_all_tweets('#Bahrain')
# # tweets = sentimentAnalysis(data)
# str = ''
# for i in data:
# str += i[2]+'\n'
data = trending_topics()
return render_template('dalvonic-home.html', page_title='Dalvonic', data=data)
@app.route('/graph')
def hi():
query = '#'+request.args.get('q')
user = ''+request.args.get('u')
if user == '' and query == '#':
data = trending_topics()
return render_template('dalvonic-home.html', page_title='Dalvonic', data=data)
elif query == '#':
outTweets = get_user_tweets(user)
elif user == '':
user = 'None'
outTweets = get_all_tweets(query)
else:
cleanUserTweets = []
if user!='None':
userTweets = get_user_tweets(user)
for i in userTweets:
if i[0].decode("utf-8").find(query)!= -1:
cleanUserTweets.append(i)
outTweets = get_all_tweets(query)
outTweets.extend(cleanUserTweets)
#searches throught user tweets and matches querys
data = preprocessTweets(outTweets)
return render_template('graph.html', page_title='Dalvonic', data=map(json.dumps, data))
#call to tweetdump with topic hashtag input
#pass tweetdump output to sentAnalysis
#Pass complete tweet topic info to front end for display.
def byteify(input):
if isinstance(input, dict):
return {byteify(key): byteify(value)
for key, value in input.iteritems()}
elif isinstance(input, list):
return [byteify(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input
if __name__=="__main__":
app.run(debug=True)