-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.py
41 lines (28 loc) · 1.04 KB
/
main.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
from flask import Flask,render_template,request,jsonify
import tweepy
from textblob import TextBlob
#---------------------------------------------------------------------------
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#-------------------------------------------------------------------------
app = Flask(__name__)
@app.route("/")
def index():
return render_template('index.html')
@app.route("/search",methods=["POST"])
def search():
search_tweet = request.form.get("search_query")
t = []
tweets = api.search(search_tweet, tweet_mode='extended')
for tweet in tweets:
polarity = TextBlob(tweet.full_text).sentiment.polarity
subjectivity = TextBlob(tweet.full_text).sentiment.subjectivity
t.append([tweet.full_text,polarity,subjectivity])
# t.append(tweet.full_text)
return jsonify({"success":True,"tweets":t})
app.run()