-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstream_code.py
More file actions
33 lines (26 loc) · 908 Bytes
/
Copy pathstream_code.py
File metadata and controls
33 lines (26 loc) · 908 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
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
from config import CONSUMER_KEY, CONSUMER_SECRET
from config import ACCESS_TOKEN, ACCESS_TOKEN_SECRET
from info import data
# OAuth process
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# listener that handles streaming data
class listener(StreamListener):
def on_connect(self):
print('Stream starting...')
def on_status(self, status):
if status.geo is not None:
t = dict()
t['text'] = status.text
t['coordinates'] = status.coordinates
data.append(t)
def on_error(self, status):
print(status)
def main():
twitterStream = Stream(auth, listener())
twitterStream.filter(locations=[
-130.78125, -31.3536369415, 140.625, 63.8600358954
])