- if domain == c['USER_DOMAIN']:
- tweet_iter = stream.user(**query_args)
- elif domain == c['SITE_DOMAIN']:
- tweet_iter = stream.site(**query_args)
- else:
- if args.track_keywords:
- tweet_iter = stream.statuses.filter(**query_args)
- else:
- tweet_iter = stream.statuses.sample()
- # Block new stream until other one exits
- StreamLock.acquire()
- g['stream_stop'] = False
- last_tweet_time = time.time()
- for tweet in tweet_iter:
- if tweet is None:
- printNicely("-- None --")
- elif tweet is Timeout:
- # Because the stream check for each 0.3s
- # so we shouldn't output anything here
- if(g['stream_stop']):
- StreamLock.release()
- break
- elif tweet is HeartbeatTimeout:
- printNicely("-- Heartbeat Timeout --")
- reconn_notice()
- StreamLock.release()
- break
- elif tweet is Hangup:
- printNicely("-- Hangup --")
- reconn_notice()
- StreamLock.release()
- break
- elif tweet.get('text'):
- # Slow down the stream by STREAM_DELAY config key
- if time.time() - last_tweet_time < c['STREAM_DELAY']:
- continue
- last_tweet_time = time.time()
- # Check the semaphore pause and lock (stream process only)
- if g['pause']:
- continue
- while c['lock']:
- time.sleep(0.5)
- # Draw the tweet
- draw(
- t=tweet,
- keyword=args.track_keywords,
- humanize=False,
- fil=args.filter,
- ig=args.ignore,
- )
- # Current readline buffer
- current_buffer = readline.get_line_buffer().strip()
- # 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:
- sys.stdout.write(
- g['decorated_name'](c['PREFIX']) + str2u(current_buffer))
- sys.stdout.flush()
- elif not c['HIDE_PROMPT']:
- sys.stdout.write(g['decorated_name'](c['PREFIX']))
- sys.stdout.flush()
- elif tweet.get('direct_message'):
- # Check the semaphore pause and lock (stream process only)
- if g['pause']:
- continue
- while c['lock']:
- time.sleep(0.5)
- print_message(tweet['direct_message'])
- elif tweet.get('event'):
- c['events'].append(tweet)
- print_event(tweet)
- except TwitterHTTPError:
- printNicely('')
- printNicely(
- magenta("We have maximum connection problem with twitter'stream API right now :("))
+ owner, slug = check_slug(stuff)
+ except:
+ owner, slug = get_slug()
+
+ # Force python 2 not redraw readline buffer
+ listname = '/'.join([owner, slug])
+ # Set the listname variable
+ # and reset tracked keyword
+ g['listname'] = listname
+ g['keyword'] = ''
+ g['PREFIX'] = g['cmd'] = u2str(emojize(format_prefix(
+ listname=g['listname']
+ )))
+ printNicely(light_yellow('getting list members ...'))
+ # Get members
+ t = Twitter(auth=authen())
+ members = []
+ next_cursor = -1
+ while next_cursor != 0:
+ m = t.lists.members(
+ slug=slug,
+ owner_screen_name=owner,
+ cursor=next_cursor,
+ include_entities=False)
+ for u in m['users']:
+ members.append('@' + u['screen_name'])
+ next_cursor = m['next_cursor']
+ printNicely(light_yellow('... done.'))
+ # Build thread filter array
+ args.filter = members
+ # Start new thread
+ th = threading.Thread(
+ target=stream,
+ args=(
+ c['USER_DOMAIN'],
+ args,
+ slug))
+ th.daemon = True
+ th.start()
+ printNicely('')
+ if args.filter:
+ printNicely(cyan('Include: ' + str(len(args.filter)) + ' people.'))
+ if args.ignore:
+ printNicely(red('Ignore: ' + str(len(args.ignore)) + ' people.'))
+ printNicely('')
+
+
+def spawn_personal_stream(args, stuff=None):
+ """
+ Spawn a new personal stream
+ """
+ # Reset the tracked keyword and listname
+ g['keyword'] = g['listname'] = ''
+ # Reset prefix
+ g['PREFIX'] = u2str(emojize(format_prefix()))
+ # Start new thread
+ th = threading.Thread(
+ target=stream,
+ args=(
+ c['USER_DOMAIN'],
+ args,
+ g['original_name']))
+ th.daemon = True
+ th.start()