summaryrefslogtreecommitdiff
path: root/htt.py
diff options
context:
space:
mode:
Diffstat (limited to 'htt.py')
-rwxr-xr-xhtt.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/htt.py b/htt.py
index d50156f..dcfd92d 100755
--- a/htt.py
+++ b/htt.py
@@ -9,6 +9,7 @@ from tweepy.streaming import StreamListener
from auth import *
from config import hashtags, white_kwds
from db import LikeMemory
+from users import listen_to_users
import json
import sys
@@ -16,7 +17,7 @@ import sys
class StdOutListener(StreamListener):
"""A listener handles tweets are the received from the stream."""
- def __init__(self, api, memory):
+ def __init__(self, api, memory, tempo):
"""Build the Python object."""
super().__init__()
@@ -24,6 +25,9 @@ class StdOutListener(StreamListener):
self._api = api
self._memory = memory
+ self._tempo = tempo
+ self._previous = None
+
self._white = [ s.lower() for s in white_kwds.split(' ') ]
@@ -52,8 +56,17 @@ class StdOutListener(StreamListener):
decoded = json.loads(data)
if 'retweeted_status' in decoded:
+
+ if not ('id' in decoded['retweeted_status']):
+ print(decoded)
+
sid, username, content = self.get_status_info(decoded['retweeted_status'])
+
else:
+
+ if not ('id' in decoded):
+ print(decoded)
+
sid, username, content = self.get_status_info(decoded)
like = False
@@ -76,8 +89,19 @@ class StdOutListener(StreamListener):
try:
- self._api.create_favorite(sid)
+ if self._tempo:
+ if self._previous != None:
+
+ self._api.create_favorite(self._previous)
+
+ self._previous = sid
+
+ else:
+
+ self._api.create_favorite(sid)
+
+ # Save even pending statuses to remember them when looking for original content
self._memory.save_liked_status(sid, username, content)
print('@%s: "%s" (id=%d)' % (username, content, sid))
@@ -114,8 +138,8 @@ if __name__ == '__main__':
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
- api = tweepy.API(auth)
- memory = LikeMemory(api)
+ api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
+ #memory = LikeMemory(api)
if len(sys.argv) > 1 and sys.argv[1] == '--purge':
@@ -123,7 +147,9 @@ if __name__ == '__main__':
else:
- listener = StdOutListener(api, memory)
+ listen_to_users(auth, api)
+
+ #listener = StdOutListener(api, memory, True)
- stream = Stream(auth, listener)
- stream.filter(track=hashtags.split(' '))
+ #stream = Stream(auth, listener)
+ #stream.filter(track=hashtags.split(' '))