-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupajank.py
59 lines (51 loc) · 1.72 KB
/
supajank.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy import API
from tweepy import error as tweepyerror
from ConfigParser import SafeConfigParser
from json import loads
from HTMLParser import HTMLParser
from time import sleep
from random import randint
import supabotfire
parser = SafeConfigParser()
parser.read('supabotfire.ini')
CONSUMER_KEY = parser.get('twitter', 'consumer.key')
CONSUMER_SECRET = parser.get('twitter', 'consumer.secret')
ACCESS_KEY = parser.get('twitter', 'access.key')
ACCESS_SECRET = parser.get('twitter', 'access.secret')
class StdOutListener(StreamListener):
def __init__(self):
self.processor = supabotfire.supa_bot_fire
def on_data(self, data):
try:
parsed_data = loads(data)
text = parsed_data['text']
h = HTMLParser()
text = h.unescape(text)
status_id = parsed_data['id']
message = self.processor(text, parsed_data['user']['screen_name'])
if message == "":
pass
else:
try:
print message
api.update_status(status=message, in_reply_to_status_id=status_id)
return False
except tweepyerror.TweepError:
pass
except KeyError:
pass
return True
def on_error(self, status):
print status
if __name__ == '__main__':
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = API(auth)
l = StdOutListener()
stream = Stream(auth, l)
while True:
stream.filter(track=['I', 'we'])
sleep(randint(0, 60*60))