-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
28 lines (22 loc) · 884 Bytes
/
common.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
import tweepy
from tweepy.streaming import StreamListener
from credentials import *
def getAuthentication():
try:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
return auth
except:
return None
def process_errors(errors):
print "Error Occurred"
print errors
# Extend the built in StreamListener class to determine how we handle the events generated by the streaming api
# The events overloaded can be found in the source code at: https://github.com/tweepy/tweepy/blob/v2.3.0/tweepy/streaming.py
class MyBasicListener(StreamListener):
def on_error(self, status_code):
process_errors(repr(status_code))
return True #Returning False will stop stream and close connection
def on_data(self, data): # Note overloading this message will affect how the on_event methods work
print data
return True