-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguardsman.py
37 lines (28 loc) · 1.16 KB
/
guardsman.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
import tweepy
import json
from haiku import Haiku
with open('access.json') as f:
secrets = json.load(f)
auth = tweepy.OAuthHandler(secrets['consumer_key'], secrets['consumer_secret_key'])
auth.set_access_token(secrets['access_token'], secrets['secret_access_token'])
class CustomStreamListener(tweepy.StreamListener):
def __init__(self):
self.haiku = Haiku()
# Load auth
with open('access.json') as f:
secrets = json.load(f)
auth = tweepy.OAuthHandler(secrets['consumer_key'], secrets['consumer_secret_key'])
auth.set_access_token(secrets['access_token'], secrets['secret_access_token'])
self.api = tweepy.API(auth)
def on_status(self, status):
print status.text
print status.user.screen_name
self.api.update_status('@'+status.user.screen_name+' '+self.haiku.insult()['result'], in_reply_to_status_id = status.id)
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
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=['@frenchguardsman'])