-
Notifications
You must be signed in to change notification settings - Fork 0
/
LetsTalkBellBot.py
38 lines (31 loc) · 1.12 KB
/
LetsTalkBellBot.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
import tweepy
import sys
import os
from keys import keys, usr # create a keys file in the format of samplekeys
consumer_key = keys['consumer_key']
consumer_secret = keys['consumer_secret']
access_key = keys['access_key']
access_secret = keys['access_secret']
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
use = os.environ.get('TW_USERNAME')
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
use = os.environ.get('TW_USERNAME')
try:
if status.retweeted:
return
if status.user.screen_name.lower() == usr:
return
return api.retweet(id=status.id)
except:
return True
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
streamingAPI = tweepy.streaming.Stream(auth, CustomStreamListener())
streamingAPI.filter(track=['#BellLetsTalk, #BellCause'])