-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
83 lines (59 loc) · 2.39 KB
/
app.py
File metadata and controls
83 lines (59 loc) · 2.39 KB
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
#
from flask import (Flask, jsonify, render_template)
from flask import request
from twitter_streamer import StdOutListener
from tweepy import Stream, OAuthHandler
from coinmarketcap import Market
import time , datetime
cmp = Market()
#from config import consumer_key, consumer_secret, access_token, access_token_secret
app = Flask(__name__)
#Twitter Credentials
consumer_key = ["YfsfRUtv0Jstlvm0TLg8DA","M7GxfzCQPOeQ8Rcm48Hskv","dXN0Ko3CdQogLJ4Iy24Vl5"]
consumer_secret = ["Dx95SabGPVACrlQanwkajOnsfsWsyej8xO8rUKnf6N70Tyh","Q5U8K0p8nMHYjvxll6V1H6CvNc4XUKHxDdqM0JioGNkej3r","e9egS4TuYYYIN5m2JM3rTv7FuhAL7mYkIRGJlZwS4sWm9G3"]
access_token= ["704330902432669696-pmTtYoAM3ywiaY5sWAEVkzhWUwan","216206580m17ST1Tt26bUscsSICz3aXptrwswOyipGc6x61","928942458511360-5U6duPS5q6duwywioruXCDIX0JJmfL6"]
access_token_secret=["BSW1LmSmDZmNrDPL3KytWXTHo99Ee1vDu1FBc5EAJ","93DS5hJ1NQnhRar2pH59QEO3LKD3njP5A9SfobZfYm","xiYtT57LbgqqPxmRyy6o9VGwKdY0FckYBDm1LKNqCw"]
# OAuth process
auth = OAuthHandler(consumer_key[2], consumer_secret[2])
auth.set_access_token(access_token[2], access_token_secret[2])
l = StdOutListener()
stream = Stream(auth, l)
''' Keywords '''
bit_coin = ['btc', 'BTC', 'Bitcoin', 'bitcoin']
rip_coin = ['ripple', 'RIPPLE']
eth_coin = ['etherium', 'eth', 'ETH', 'ETHERIUM']
Keyword = bit_coin
@app.route('/')
def index():
return render_template('newindex3.html')
@app.route('/server_reload', methods=['POST', 'GET'])
def server_reload():
data_retrieved = request.form.get('x')
global Keyword
if data_retrieved == 'bitcoin':
Keyword = bit_coin
elif data_retrieved == 'ripple':
Keyword = rip_coin
elif data_retrieved == 'etherium':
Keyword = eth_coin
stream.disconnect()
currentTime = l.df.RealTime.max()
xMinAgoTime = currentTime - datetime.timedelta(minutes=0.01)
l.df = l.df.loc[l.df['RealTime'] > xMinAgoTime]
l.df = l.df.reset_index(drop=True)
stream.filter(track = Keyword, async=True)
return "varad"
@app.route('/ajax', methods=['POST', 'GET'])
def ajax_request():
print(Keyword)
global stream
try:
stream.filter(track = Keyword, async=True)
except Exception as e:
print('Debugging')
score = round(l.df.Sentiment.mean(), 4)
numTweets = len(l.df)
lh=cmp.ticker("AUD",limit=1,convert='USD')
return jsonify(score=score, numTweets = numTweets)
if __name__ == "__main__":
app.run(debug=True)