diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 756604e2..b9110df7 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -210,7 +210,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): t['event'] = 'retweet' c['events'].append(t) notify_retweet(t) - return + return True except: pass @@ -250,9 +250,9 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): fil = list(set((fil or []) + c['ONLY_LIST'])) ig = list(set((ig or []) + c['IGNORE_LIST'])) if fil and screen_name not in fil: - return + return False if ig and screen_name in ig: - return + return False # Get rainbow id if tid not in c['tweet_dict']: @@ -375,6 +375,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): image_to_display(BytesIO(response.content)) except Exception: printNicely(red('Sorry, image link is broken')) + return True def print_threads(d): diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 465299f0..bf253dd6 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -2010,20 +2010,22 @@ def stream(domain, args, name='Rainbow Stream'): # The Logo art_dict = { c['USER_DOMAIN']: name, - c['PUBLIC_DOMAIN']: args.track_keywords or 'Global', + c['PUBLIC_DOMAIN']: args.track_keywords or name or 'Global', c['SITE_DOMAIN']: name, } if c['ASCII_ART']: ascii_art(art_dict.get(domain, name)) # These arguments are optional: stream_args = dict( - timeout=0.5, # To check g['stream_stop'] after each 0.5 s + timeout=0.25, # To check g['stream_stop'] after each 0.5 s block=True, heartbeat_timeout=c['HEARTBEAT_TIMEOUT'] * 60) # Track keyword query_args = dict() if args.track_keywords: query_args['track'] = args.track_keywords + if args.filter_ids: + query_args['follow'] = args.filter_ids # Get stream stream = TwitterStream( auth=authen(), @@ -2035,7 +2037,7 @@ def stream(domain, args, name='Rainbow Stream'): elif domain == c['SITE_DOMAIN']: tweet_iter = stream.site(**query_args) else: - if args.track_keywords: + if args.track_keywords or args.filter_ids: tweet_iter = stream.statuses.filter(**query_args) else: tweet_iter = stream.statuses.sample() @@ -2071,9 +2073,9 @@ def stream(domain, args, name='Rainbow Stream'): if g['pause']: continue while c['lock']: - time.sleep(0.5) + time.sleep(0.25) # Draw the tweet - draw( + did_draw = draw( t=tweet, keyword=args.track_keywords, humanize=False, @@ -2081,12 +2083,12 @@ def stream(domain, args, name='Rainbow Stream'): ig=args.ignore, ) # Current readline buffer - current_buffer = readline.get_line_buffer().strip() + current_buffer = readline.get_line_buffer() # There is an unexpected behaviour in MacOSX readline + Python 2: # after completely delete a word after typing it, # somehow readline buffer still contains # the 1st character of that word - if current_buffer and g['cmd'] != current_buffer: + if current_buffer and g['cmd'] != current_buffer and did_draw: sys.stdout.write( g['decorated_name'](g['PREFIX']) + current_buffer) sys.stdout.flush() @@ -2098,7 +2100,7 @@ def stream(domain, args, name='Rainbow Stream'): if g['pause']: continue while c['lock']: - time.sleep(0.5) + time.sleep(0.25) print_message(tweet['direct_message']) elif tweet.get('event'): c['events'].append(tweet) @@ -2122,6 +2124,7 @@ def spawn_public_stream(args, keyword=None): Spawn a new public stream """ # Only set keyword if specified + args.filter_ids = '' if keyword: if keyword[0] == '#': keyword = keyword[1:] @@ -2131,6 +2134,7 @@ def spawn_public_stream(args, keyword=None): g['keyword'] = 'Global' g['PREFIX'] = u2str(emojize(format_prefix(keyword=g['keyword']))) g['listname'] = '' + # Start new thread th = threading.Thread( target=stream, @@ -2162,7 +2166,7 @@ def spawn_list_stream(args, stuff=None): printNicely(light_yellow('getting list members ...')) # Get members t = Twitter(auth=authen()) - members = [] + members, member_ids = [], [] next_cursor = -1 while next_cursor != 0: m = t.lists.members( @@ -2172,15 +2176,18 @@ def spawn_list_stream(args, stuff=None): include_entities=False) for u in m['users']: members.append('@' + u['screen_name']) + member_ids.append(u['id']) next_cursor = m['next_cursor'] printNicely(light_yellow('... done.')) # Build thread filter array args.filter = members + args.filter_ids = ','.join([str(x) for x in member_ids]) + # Start new thread th = threading.Thread( target=stream, args=( - c['USER_DOMAIN'], + c['PUBLIC_DOMAIN'], args, slug)) th.daemon = True @@ -2197,6 +2204,7 @@ def spawn_personal_stream(args, stuff=None): """ Spawn a new personal stream """ + args.filter_ids = '' # Reset the tracked keyword and listname g['keyword'] = g['listname'] = '' # Reset prefix @@ -2254,7 +2262,7 @@ def fly(): spawn_dict.get(target)(args, stuff) # Start listen process - time.sleep(0.5) + time.sleep(0.25) g['reset'] = True g['prefix'] = True listen()