-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistener.py
42 lines (32 loc) · 1.06 KB
/
listener.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
import tweepy
import pprint
pp = pprint.PrettyPrinter(indent=4)
class SimpleListener(tweepy.StreamListener):
def __init__(self, api):
super().__init__(api)
self.me = api.me()
self.api = api
def on_status(self, status):
if status.in_reply_to_status_id is not None or \
status.user.id == self.me.id:
print(status.text, " is your own tweet")
try:
status.favorite()
except Exception as e:
print(e)
return
try:
status.favorite()
status.retweet()
except Exception as e:
print(e)
# def on_direct_message(self, status):
# # code to run each time the stream receives a direct message
# pp.pprint(status.text)
# def on_data(self, status):
# # code to run each time you receive some data (direct message, delete, profile update, status,...)
# pp.pprint(status)
def on_error(self, status):
print(status)
# initialize the stream
# api = create_api()