-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
39 lines (29 loc) · 1002 Bytes
/
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Twitter Sentiment Analysis
@author: Pratik Barjatiya
"""
import os
from flask import Flask, request, render_template, jsonify
from twitter import TwitterClient
app = Flask(__name__)
# Setup the client <query string, retweets_only bool, with_sentiment bool>
api = TwitterClient('@pratik007a')
def strtobool(v):
return v.lower() in ["yes", "true", "t", "1"]
@app.route('/')
def index():
return render_template('index.html')
@app.route('/tweets')
def tweets():
retweets_only = request.args.get('retweets_only')
api.set_retweet_checking(strtobool(retweets_only.lower()))
with_sentiment = request.args.get('with_sentiment')
api.set_with_sentiment(strtobool(with_sentiment.lower()))
query = request.args.get('query')
api.set_query(query)
tweets = api.get_tweets()
return jsonify({'data': tweets, 'count': len(tweets)})
port = int(os.environ.get('PORT', 5000))
app.run(host="0.0.0.0", port=port, debug=True)