-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
60 lines (51 loc) · 1.84 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
from flask import Flask,render_template,request,jsonify
from flask.templating import render_template
import subprocess
# pandas not used here ?
# import pandas as pd
import csv
from sentiment import sentimentCount
from hash_src import sourceCount,hashtagCount
from tweetsFilter import tweetsFilter
app=Flask(__name__)
app.debug=True
# @app.after_request
# def add_header(response):
# """
# Add headers to both force latest IE rendering engine or Chrome Frame,
# and also to cache the rendered page for 10 minutes.
# """
# response.headers['Cache-Control'] = 'no-store'
# return response
@app.route('/',methods=['GET','POST'])
def home():
return render_template('home.html')
# @csrf.exempt
@app.route('/search-form',methods=['GET','POST'])
def tweet():
request_method=request.method
if request.method=="POST":
post=request.form['search']
cmd=' python "./twitter_search.py " {}'.format(post)
p=subprocess.run(cmd,shell=True)
return jsonify({'success':True}), 200, {'ContentType':'application/json'}
# return render_template('home.html', searchTerm = post)
@app.route('/senti-button', methods=['GET','POST'])
def giveSentiData():
pos,neg,neut = sentimentCount()
# return '{} {} {}'.format(pos, neg, neut)
return jsonify(["Sentiment","Count"],["Positive", pos],["Negative", neg],["Neutral", neut])
@app.route('/source-button', methods=['GET','POST'])
def giveSourceData():
src = sourceCount()
return jsonify([["Source","Count"]] + src)
@app.route('/hashtag-button', methods=['GET','POST'])
def giveHashtagData():
topThreeHashtag = hashtagCount()[0:3]
return jsonify(topThreeHashtag)
@app.route('/tweets-button', methods=['GET'])
def displayAllTweets():
btnPos = list(request.args.keys())[0];
return tweetsFilter(int(btnPos))
if __name__=="__main__":
app.run(debug=True)