-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtwitter_streaming_api.py
More file actions
41 lines (31 loc) · 882 Bytes
/
twitter_streaming_api.py
File metadata and controls
41 lines (31 loc) · 882 Bytes
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 tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
import json
######################
## Load API Tokens
######################
tokenfile = open('/Users/psehgal/dev/Sentiment.Analysis/twitter_tokens.json')
tokens = json.load(tokenfile)
ckey = tokens['ckey']
csecret = tokens['csecret']
atoken = tokens['atoken']
asecret = tokens['asecret']
######################
## Create listener class
######################
class listener(StreamListener):
def on_data(self, data):
print(data)
return(True)
def on_error(self, status):
print(status)
######################
## main program
######################
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["$TSLA"])
########################