16 from io
import BytesIO
17 from twitter
.stream
import TwitterStream
, Timeout
, HeartbeatTimeout
, Hangup
18 from twitter
.api
import *
19 from twitter
.oauth
import OAuth
, read_token_file
20 from twitter
.oauth_dance
import oauth_dance
21 from twitter
.util
import printNicely
26 from .consumer
import *
27 from .interactive
import *
28 from .c_image
import *
29 from .py3patch
import *
37 StreamLock
= threading
.Lock()
40 def parse_arguments():
44 parser
= argparse
.ArgumentParser(description
=__doc__
or "")
50 help='Default stream after program start. (Default: mine)')
54 help='Timeout for the stream (seconds).')
58 help='Search the stream for specific text.')
62 help='Filter specific screen_name.')
66 help='Ignore specific screen_name.')
71 help='Display all image on terminal.')
75 help='Use HTTP/SOCKS proxy for network connections.')
80 help='HTTP/SOCKS proxy port (Default: 8080).')
85 help='Proxy type (HTTP, SOCKS4, SOCKS5; Default: SOCKS5).')
86 return parser
.parse_args()
89 def proxy_connect(args
):
91 Connect to specified proxy
94 # Setup proxy by monkeypatching the standard lib
95 if args
.proxy_type
.lower() == "socks5" or not args
.proxy_type
:
96 socks
.set_default_proxy(
97 socks
.SOCKS5
, args
.proxy_host
,
99 elif args
.proxy_type
.lower() == "http":
100 socks
.set_default_proxy(
101 socks
.HTTP
, args
.proxy_host
,
102 int(args
.proxy_port
))
103 elif args
.proxy_type
.lower() == "socks4":
104 socks
.set_default_proxy(
105 socks
.SOCKS4
, args
.proxy_host
,
106 int(args
.proxy_port
))
109 magenta('Sorry, wrong proxy type specified! Aborting...'))
111 socket
.socket
= socks
.socksocket
116 Authenticate with Twitter OAuth
118 # When using rainbow stream you must authorize.
119 twitter_credential
= os
.environ
.get(
123 '')) + os
.sep
+ '.rainbow_oauth'
124 if not os
.path
.exists(twitter_credential
):
125 oauth_dance('Rainbow Stream',
129 oauth_token
, oauth_token_secret
= read_token_file(twitter_credential
)
137 def build_mute_dict(dict_data
=False):
141 t
= Twitter(auth
=authen())
144 screen_name_list
= []
147 while next_cursor
!= 0:
148 list = t
.mutes
.users
.list(
149 screen_name
=g
['original_name'],
152 include_entities
=False,
154 screen_name_list
+= ['@' + u
['screen_name'] for u
in list['users']]
155 name_list
+= [u
['name'] for u
in list['users']]
156 next_cursor
= list['next_cursor']
157 # Return dict or list
159 return dict(zip(screen_name_list
, name_list
))
161 return screen_name_list
166 Save traceback when run in debug mode
169 g
['traceback'].append(traceback
.format_exc())
172 def upgrade_center():
174 Check latest and notify to upgrade
177 current
= pkg_resources
.get_distribution('rainbowstream').version
178 url
= 'https://raw.githubusercontent.com/DTVD/rainbowstream/master/setup.py'
179 readme
= requests
.get(url
).text
180 latest
= readme
.split('version = \'')[1].split('\'')[0]
181 if current
!= latest
:
182 notice
= light_magenta('RainbowStream latest version is ')
183 notice
+= light_green(latest
)
184 notice
+= light_magenta(' while your current version is ')
185 notice
+= light_yellow(current
) + '\n'
186 notice
+= light_magenta('You should upgrade with ')
187 notice
+= light_green('pip install -U rainbowstream')
190 notice
= light_yellow('You are running latest version (')
191 notice
+= light_green(current
)
192 notice
+= light_yellow(')')
203 ctrl_c_handler
= lambda signum
, frame
: quit()
204 signal
.signal(signal
.SIGINT
, ctrl_c_handler
)
208 t
= Twitter(auth
=authen())
209 credential
= t
.account
.verify_credentials()
210 screen_name
= '@' + credential
['screen_name']
211 name
= credential
['name']
212 c
['original_name'] = g
['original_name'] = screen_name
[1:]
213 g
['listname'] = g
['keyword'] = ''
214 g
['PREFIX'] = u2str(emojize(format_prefix()))
215 g
['full_name'] = name
216 g
['decorated_name'] = lambda x
: color_func(
217 c
['DECORATED_NAME'])('[' + x
+ ']: ', rl
=True)
219 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
220 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
223 g
['message_threads'] = {}
226 # Debug option default = True
233 # Init tweet dict and message dict
235 c
['message_dict'] = []
237 c
['IMAGE_ON_TERM'] = args
.image_on_term
238 set_config('IMAGE_ON_TERM', str(c
['IMAGE_ON_TERM']))
239 # Check type of ONLY_LIST and IGNORE_LIST
240 if not isinstance(c
['ONLY_LIST'], list):
241 printNicely(red('ONLY_LIST is not a valid list value.'))
243 if not isinstance(c
['IGNORE_LIST'], list):
244 printNicely(red('IGNORE_LIST is not a valid list value.'))
245 c
['IGNORE_LIST'] = []
247 c
['IGNORE_LIST'] += build_mute_dict()
254 t
= Twitter(auth
=authen())
255 # Get country and town
257 country
= g
['stuff'].split()[0]
261 town
= g
['stuff'].split()[1]
264 avail
= t
.trends
.available()
267 trends
= t
.trends
.place(_id
=1)[0]['trends']
270 for location
in avail
:
271 # Search for country and Town
273 if location
['countryCode'] == country \
274 and location
['placeType']['name'] == 'Town' \
275 and location
['name'] == town
:
276 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
278 # Search for country only
280 if location
['countryCode'] == country \
281 and location
['placeType']['name'] == 'Country':
282 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
290 t
= Twitter(auth
=authen())
291 num
= c
['HOME_TWEET_NUM']
292 if g
['stuff'].isdigit():
293 num
= int(g
['stuff'])
294 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
304 for e
in c
['events']:
308 printNicely(magenta('Nothing at this time.'))
315 t
= Twitter(auth
=authen())
316 num
= c
['HOME_TWEET_NUM']
317 if g
['stuff'].isdigit():
318 num
= int(g
['stuff'])
319 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
326 Show profile of a specific user
328 t
= Twitter(auth
=authen())
329 screen_name
= g
['stuff'].split()[0]
330 if screen_name
.startswith('@'):
333 screen_name
=screen_name
[1:],
334 include_entities
=False)
338 printNicely(red('No user.'))
340 printNicely(red('A name should begin with a \'@\''))
347 t
= Twitter(auth
=authen())
348 user
= g
['stuff'].split()[0]
351 num
= int(g
['stuff'].split()[1])
353 num
= c
['HOME_TWEET_NUM']
354 for tweet
in reversed(
355 t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
359 printNicely(red('A name should begin with a \'@\''))
366 t
= Twitter(auth
=authen())
368 query
= g
['stuff'].strip()
369 type = c
['SEARCH_TYPE']
370 if type not in ['mixed', 'recent', 'popular']:
372 max_record
= c
['SEARCH_MAX_RECORD']
373 count
= min(max_record
, 100)
375 rel
= t
.search
.tweets(
382 printNicely('Newest tweets:')
383 for i
in reversed(xrange(count
)):
384 draw(t
=rel
[i
], keyword
=query
)
387 printNicely(magenta('I\'m afraid there is no result'))
394 t
= Twitter(auth
=authen())
395 t
.statuses
.update(status
=g
['stuff'])
402 t
= Twitter(auth
=authen())
404 id = int(g
['stuff'].split()[0])
406 printNicely(red('Sorry I can\'t understand.'))
408 tid
= c
['tweet_dict'][id]
409 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
417 t
= Twitter(auth
=authen())
419 id = int(g
['stuff'].split()[0])
421 printNicely(red('Sorry I can\'t understand.'))
423 tid
= c
['tweet_dict'][id]
424 tweet
= t
.statuses
.show(id=tid
)
426 formater
= format_quote(tweet
)
430 prefix
= light_magenta('Compose your ', rl
=True) + \
431 light_green('#comment: ', rl
=True)
432 comment
= raw_input(prefix
)
434 quote
= comment
.join(formater
.split('#comment'))
435 t
.statuses
.update(status
=quote
)
437 printNicely(light_magenta('No text added.'))
444 t
= Twitter(auth
=authen())
447 id = int(g
['stuff'].split()[0])
449 printNicely(red('Sorry I can\'t understand.'))
451 tid
= c
['tweet_dict'][id]
452 # Get display num if exist
454 num
= int(g
['stuff'].split()[1])
456 num
= c
['RETWEETS_SHOW_NUM']
457 # Get result and display
458 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
460 printNicely(magenta('This tweet has no retweet.'))
462 for tweet
in reversed(rt_ary
):
471 t
= Twitter(auth
=authen())
473 id = int(g
['stuff'].split()[0])
475 printNicely(red('Sorry I can\'t understand.'))
477 tid
= c
['tweet_dict'][id]
478 tweet
= t
.statuses
.show(id=tid
)
479 limit
= c
['CONVERSATION_MAX']
481 thread_ref
.append(tweet
)
482 prev_tid
= tweet
['in_reply_to_status_id']
483 while prev_tid
and limit
:
485 tweet
= t
.statuses
.show(id=prev_tid
)
486 prev_tid
= tweet
['in_reply_to_status_id']
487 thread_ref
.append(tweet
)
489 for tweet
in reversed(thread_ref
):
498 t
= Twitter(auth
=authen())
500 id = int(g
['stuff'].split()[0])
502 printNicely(red('Sorry I can\'t understand.'))
504 tid
= c
['tweet_dict'][id]
505 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
506 status
= ' '.join(g
['stuff'].split()[1:])
507 status
= '@' + user
+ ' ' + str2u(status
)
508 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
515 t
= Twitter(auth
=authen())
517 id = int(g
['stuff'].split()[0])
519 printNicely(red('Sorry I can\'t understand.'))
521 tid
= c
['tweet_dict'][id]
522 original_tweet
= t
.statuses
.show(id=tid
)
523 text
= original_tweet
['text']
524 owner
= '@' + original_tweet
['user']['screen_name']
525 nick_ary
= ['@' + re
.sub('[\W_]', '', w
)
526 for w
in text
.split() if w
.startswith('@')] + [owner
]
527 status
= ' '.join(g
['stuff'].split()[1:])
528 status
= ' '.join(nick_ary
) + ' ' + str2u(status
)
529 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
536 t
= Twitter(auth
=authen())
538 id = int(g
['stuff'].split()[0])
540 printNicely(red('Sorry I can\'t understand.'))
542 tid
= c
['tweet_dict'][id]
543 t
.favorites
.create(_id
=tid
, include_entities
=False)
544 printNicely(green('Favorited.'))
545 draw(t
.statuses
.show(id=tid
))
553 t
= Twitter(auth
=authen())
555 id = int(g
['stuff'].split()[0])
557 printNicely(red('Sorry I can\'t understand.'))
559 tid
= c
['tweet_dict'][id]
560 t
.favorites
.destroy(_id
=tid
)
561 printNicely(green('Okay it\'s unfavorited.'))
562 draw(t
.statuses
.show(id=tid
))
568 Copy url of a tweet to clipboard
570 t
= Twitter(auth
=authen())
572 id = int(g
['stuff'].split()[0])
573 tid
= c
['tweet_dict'][id]
575 printNicely(red('Tweet id is not valid.'))
577 tweet
= t
.statuses
.show(id=tid
)
578 url
= 'https://twitter.com/' + \
579 tweet
['user']['screen_name'] + '/status/' + str(tid
)
581 if platform
.system().lower() == 'darwin':
582 os
.system("echo '%s' | pbcopy" % url
)
583 printNicely(green('Copied tweet\'s url to clipboard.'))
585 printNicely('Direct link: ' + yellow(url
))
592 t
= Twitter(auth
=authen())
594 id = int(g
['stuff'].split()[0])
596 printNicely(red('Sorry I can\'t understand.'))
598 tid
= c
['tweet_dict'][id]
599 t
.statuses
.destroy(id=tid
)
600 printNicely(green('Okay it\'s gone.'))
607 t
= Twitter(auth
=authen())
609 target
= g
['stuff'].split()[0]
610 if target
!= 'image':
612 id = int(g
['stuff'].split()[1])
613 tid
= c
['tweet_dict'][id]
614 tweet
= t
.statuses
.show(id=tid
)
615 media
= tweet
['entities']['media']
617 res
= requests
.get(m
['media_url'])
618 img
= Image
.open(BytesIO(res
.content
))
622 printNicely(red('Sorry I can\'t show this image.'))
629 t
= Twitter(auth
=authen())
631 if not g
['stuff'].isdigit():
633 tid
= c
['tweet_dict'][int(g
['stuff'])]
634 tweet
= t
.statuses
.show(id=tid
)
635 link_prefix
= ('http://', 'https://')
636 link_ary
= [u
for u
in tweet
['text'].split()
637 if u
.startswith(link_prefix
)]
639 printNicely(light_magenta('No url here @.@!'))
641 for link
in link_ary
:
642 webbrowser
.open(link
)
645 printNicely(red('Sorry I can\'t open url in this tweet.'))
652 t
= Twitter(auth
=authen())
653 num
= c
['MESSAGES_DISPLAY']
654 if g
['stuff'].isdigit():
660 inbox
= inbox
+ t
.direct_messages(
663 include_entities
=False,
668 inbox
= inbox
+ t
.direct_messages(
671 include_entities
=False,
675 num
= c
['MESSAGES_DISPLAY']
676 if g
['stuff'].isdigit():
681 sent
= sent
+ t
.direct_messages
.sent(
684 include_entities
=False,
689 sent
= sent
+ t
.direct_messages
.sent(
692 include_entities
=False,
697 uniq_inbox
= list(set(
698 [(m
['sender_screen_name'], m
['sender']['name']) for m
in inbox
]
700 uniq_sent
= list(set(
701 [(m
['recipient_screen_name'], m
['recipient']['name']) for m
in sent
]
703 for partner
in uniq_inbox
:
704 inbox_ary
= [m
for m
in inbox
if m
['sender_screen_name'] == partner
[0]]
706 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
707 d
[partner
] = inbox_ary
+ sent_ary
708 for partner
in uniq_sent
:
711 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
712 g
['message_threads'] = print_threads(d
)
717 View a thread of message
720 thread_id
= int(g
['stuff'])
722 g
['message_threads'][thread_id
],
727 printNicely(red('No such thread.'))
732 Send a direct message
734 t
= Twitter(auth
=authen())
736 user
= g
['stuff'].split()[0]
737 if user
[0].startswith('@'):
738 content
= ' '.join(g
['stuff'].split()[1:])
739 t
.direct_messages
.new(
740 screen_name
=user
[1:],
743 printNicely(green('Message sent.'))
745 printNicely(red('A name should begin with a \'@\''))
748 printNicely(red('Sorry I can\'t understand.'))
755 t
= Twitter(auth
=authen())
757 id = int(g
['stuff'].split()[0])
759 printNicely(red('Sorry I can\'t understand.'))
760 mid
= c
['message_dict'][id]
761 t
.direct_messages
.destroy(id=mid
)
762 printNicely(green('Message deleted.'))
767 List friends for followers
769 t
= Twitter(auth
=authen())
772 name
= g
['stuff'].split()[1]
773 if name
.startswith('@'):
776 printNicely(red('A name should begin with a \'@\''))
777 raise Exception('Invalid name')
779 name
= g
['original_name']
780 # Get list followers or friends
782 target
= g
['stuff'].split()[0]
784 printNicely(red('Omg some syntax is wrong.'))
786 d
= {'fl': 'followers', 'fr': 'friends'}
790 while next_cursor
!= 0:
791 list = getattr(t
, d
[target
]).list(
795 include_entities
=False,
797 for u
in list['users']:
798 rel
[u
['name']] = '@' + u
['screen_name']
799 next_cursor
= list['next_cursor']
801 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
803 user
= ' ' + cycle_color(name
)
804 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
812 t
= Twitter(auth
=authen())
813 screen_name
= g
['stuff'].split()[0]
814 if screen_name
.startswith('@'):
815 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
816 printNicely(green('You are following ' + screen_name
+ ' now!'))
818 printNicely(red('A name should begin with a \'@\''))
825 t
= Twitter(auth
=authen())
826 screen_name
= g
['stuff'].split()[0]
827 if screen_name
.startswith('@'):
828 t
.friendships
.destroy(
829 screen_name
=screen_name
[1:],
830 include_entities
=False)
831 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
833 printNicely(red('A name should begin with a \'@\''))
840 t
= Twitter(auth
=authen())
842 screen_name
= g
['stuff'].split()[0]
844 printNicely(red('A name should be specified. '))
846 if screen_name
.startswith('@'):
848 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
849 if isinstance(rel
, dict):
850 printNicely(green(screen_name
+ ' is muted.'))
851 c
['IGNORE_LIST'] += [unc(screen_name
)]
852 c
['IGNORE_LIST'] = list(set(c
['IGNORE_LIST']))
854 printNicely(red(rel
))
857 printNicely(red('Something is wrong, can not mute now :('))
859 printNicely(red('A name should begin with a \'@\''))
866 t
= Twitter(auth
=authen())
868 screen_name
= g
['stuff'].split()[0]
870 printNicely(red('A name should be specified. '))
872 if screen_name
.startswith('@'):
874 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
875 if isinstance(rel
, dict):
876 printNicely(green(screen_name
+ ' is unmuted.'))
877 c
['IGNORE_LIST'].remove(screen_name
)
879 printNicely(red(rel
))
881 printNicely(red('Maybe you are not muting this person ?'))
883 printNicely(red('A name should begin with a \'@\''))
890 # Get dict of muting users
891 md
= build_mute_dict(dict_data
=True)
892 printNicely('All: ' + str(len(md
)) + ' people.')
894 user
= ' ' + cycle_color(md
[name
])
895 user
+= color_func(c
['TWEET']['nick'])(' ' + name
+ ' ')
897 # Update from Twitter
898 c
['IGNORE_LIST'] = [n
for n
in md
]
905 t
= Twitter(auth
=authen())
906 screen_name
= g
['stuff'].split()[0]
907 if screen_name
.startswith('@'):
909 screen_name
=screen_name
[1:],
910 include_entities
=False,
912 printNicely(green('You blocked ' + screen_name
+ '.'))
914 printNicely(red('A name should begin with a \'@\''))
921 t
= Twitter(auth
=authen())
922 screen_name
= g
['stuff'].split()[0]
923 if screen_name
.startswith('@'):
925 screen_name
=screen_name
[1:],
926 include_entities
=False,
928 printNicely(green('Unblock ' + screen_name
+ ' success!'))
930 printNicely(red('A name should begin with a \'@\''))
935 Report a user as a spam account
937 t
= Twitter(auth
=authen())
938 screen_name
= g
['stuff'].split()[0]
939 if screen_name
.startswith('@'):
941 screen_name
=screen_name
[1:])
942 printNicely(green('You reported ' + screen_name
+ '.'))
944 printNicely(red('Sorry I can\'t understand.'))
952 list_name
= raw_input(
953 light_magenta('Give me the list\'s name ("@owner/list_name"): ', rl
=True))
954 # Get list name and owner
956 owner
, slug
= list_name
.split('/')
957 if slug
.startswith('@'):
962 light_magenta('List name should follow "@owner/list_name" format.'))
963 raise Exception('Wrong list name')
965 def check_slug(list_name
):
969 # Get list name and owner
971 owner
, slug
= list_name
.split('/')
972 if slug
.startswith('@'):
977 light_magenta('List name should follow "@owner/list_name" format.'))
978 raise Exception('Wrong list name')
984 rel
= t
.lists
.list(screen_name
=g
['original_name'])
988 printNicely(light_magenta('You belong to no lists :)'))
995 owner
, slug
= get_slug()
996 res
= t
.lists
.statuses(
998 owner_screen_name
=owner
,
1000 include_entities
=False)
1001 for tweet
in reversed(res
):
1006 def list_members(t
):
1010 owner
, slug
= get_slug()
1014 while next_cursor
!= 0:
1015 m
= t
.lists
.members(
1017 owner_screen_name
=owner
,
1019 include_entities
=False)
1020 for u
in m
['users']:
1021 rel
[u
['name']] = '@' + u
['screen_name']
1022 next_cursor
= m
['next_cursor']
1023 printNicely('All: ' + str(len(rel
)) + ' members.')
1025 user
= ' ' + cycle_color(name
)
1026 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1030 def list_subscribers(t
):
1034 owner
, slug
= get_slug()
1038 while next_cursor
!= 0:
1039 m
= t
.lists
.subscribers(
1041 owner_screen_name
=owner
,
1043 include_entities
=False)
1044 for u
in m
['users']:
1045 rel
[u
['name']] = '@' + u
['screen_name']
1046 next_cursor
= m
['next_cursor']
1047 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
1049 user
= ' ' + cycle_color(name
)
1050 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1056 Add specific user to a list
1058 owner
, slug
= get_slug()
1060 user_name
= raw_input(
1062 'Give me name of the newbie: ',
1064 if user_name
.startswith('@'):
1065 user_name
= user_name
[1:]
1067 t
.lists
.members
.create(
1069 owner_screen_name
=owner
,
1070 screen_name
=user_name
)
1071 printNicely(green('Added.'))
1074 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
1079 Remove specific user from a list
1081 owner
, slug
= get_slug()
1083 user_name
= raw_input(
1085 'Give me name of the unlucky one: ',
1087 if user_name
.startswith('@'):
1088 user_name
= user_name
[1:]
1090 t
.lists
.members
.destroy(
1092 owner_screen_name
=owner
,
1093 screen_name
=user_name
)
1094 printNicely(green('Gone.'))
1097 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
1100 def list_subscribe(t
):
1104 owner
, slug
= get_slug()
1107 t
.lists
.subscribers
.create(
1109 owner_screen_name
=owner
)
1110 printNicely(green('Done.'))
1114 light_magenta('I\'m sorry you can not subscribe to this list.'))
1117 def list_unsubscribe(t
):
1121 owner
, slug
= get_slug()
1124 t
.lists
.subscribers
.destroy(
1126 owner_screen_name
=owner
)
1127 printNicely(green('Done.'))
1131 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
1140 while next_cursor
!= 0:
1141 res
= t
.lists
.ownerships(
1142 screen_name
=g
['original_name'],
1145 next_cursor
= res
['next_cursor']
1149 printNicely(light_magenta('You own no lists :)'))
1156 name
= raw_input(light_magenta('New list\'s name: ', rl
=True))
1159 'New list\'s mode (public/private): ',
1161 description
= raw_input(
1163 'New list\'s description: ',
1169 description
=description
)
1170 printNicely(green(name
+ ' list is created.'))
1173 printNicely(red('Oops something is wrong with Twitter :('))
1182 'Your list that you want to update: ',
1186 'Update name (leave blank to unchange): ',
1188 mode
= raw_input(light_magenta('Update mode (public/private): ', rl
=True))
1189 description
= raw_input(light_magenta('Update description: ', rl
=True))
1193 slug
='-'.join(slug
.split()),
1194 owner_screen_name
=g
['original_name'],
1197 description
=description
)
1201 owner_screen_name
=g
['original_name'],
1203 description
=description
)
1204 printNicely(green(slug
+ ' list is updated.'))
1207 printNicely(red('Oops something is wrong with Twitter :('))
1216 'Your list that you want to delete: ',
1220 slug
='-'.join(slug
.split()),
1221 owner_screen_name
=g
['original_name'])
1222 printNicely(green(slug
+ ' list is deleted.'))
1225 printNicely(red('Oops something is wrong with Twitter :('))
1232 t
= Twitter(auth
=authen())
1233 # List all lists or base on action
1235 g
['list_action'] = g
['stuff'].split()[0]
1242 'all_mem': list_members
,
1243 'all_sub': list_subscribers
,
1246 'sub': list_subscribe
,
1247 'unsub': list_unsubscribe
,
1250 'update': list_update
,
1254 return action_ary
[g
['list_action']](t
)
1256 printNicely(red('Please try again.'))
1264 target
= g
['stuff'].split()[0]
1266 args
= parse_arguments()
1268 if g
['stuff'].split()[-1] == '-f':
1269 guide
= 'To ignore an option, just hit Enter key.'
1270 printNicely(light_magenta(guide
))
1271 only
= raw_input('Only nicks [Ex: @xxx,@yy]: ')
1272 ignore
= raw_input('Ignore nicks [Ex: @xxx,@yy]: ')
1273 args
.filter = filter(None, only
.split(','))
1274 args
.ignore
= filter(None, ignore
.split(','))
1276 printNicely(red('Sorry, wrong format.'))
1279 if target
== 'public':
1280 keyword
= g
['stuff'].split()[1]
1281 if keyword
[0] == '#':
1282 keyword
= keyword
[1:]
1284 g
['stream_stop'] = True
1285 args
.track_keywords
= keyword
1286 # Set the variable to tracked keyword
1287 # and reset the listname
1288 g
['keyword'] = keyword
1291 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
1293 th
= threading
.Thread(
1301 elif target
== 'mine':
1303 g
['stream_stop'] = True
1304 # Reset the tracked keyword and listname
1305 g
['keyword'] = g
['listname'] = ''
1307 g
['PREFIX'] = u2str(emojize(format_prefix()))
1309 th
= threading
.Thread(
1314 g
['original_name']))
1317 # Stream base on list
1318 elif target
== 'list':
1319 owner
, slug
= get_slug()
1320 # Force python 2 not redraw readline buffer
1321 listname
= '/'.join([owner
, slug
])
1322 # Set the listname variable
1323 # and reset tracked keyword
1324 g
['listname'] = listname
1326 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
1327 listname
=g
['listname']
1329 printNicely(light_yellow('getting list members ...'))
1331 t
= Twitter(auth
=authen())
1334 while next_cursor
!= 0:
1335 m
= t
.lists
.members(
1337 owner_screen_name
=owner
,
1339 include_entities
=False)
1340 for u
in m
['users']:
1341 members
.append('@' + u
['screen_name'])
1342 next_cursor
= m
['next_cursor']
1343 printNicely(light_yellow('... done.'))
1344 # Build thread filter array
1345 args
.filter = members
1347 g
['stream_stop'] = True
1349 th
= threading
.Thread(
1359 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
1361 printNicely(red('Ignore: ' + str(len(args
.ignore
)) + ' people.'))
1365 printNicely(red('Sorry I can\'t understand.'))
1370 Unix's command `cal`
1373 rel
= os
.popen('cal').read().split('\n')
1376 show_calendar(month
, date
, rel
)
1381 List and change theme
1385 for theme
in g
['themes']:
1386 line
= light_magenta(theme
)
1387 if c
['THEME'] == theme
:
1388 line
= ' ' * 2 + light_yellow('* ') + line
1390 line
= ' ' * 4 + line
1396 c
['THEME'] = reload_theme(g
['stuff'], c
['THEME'])
1397 # Redefine decorated_name
1398 g
['decorated_name'] = lambda x
: color_func(
1399 c
['DECORATED_NAME'])(
1401 printNicely(green('Theme changed.'))
1403 printNicely(red('No such theme exists.'))
1408 Browse and change config
1410 all_config
= get_all_config()
1411 g
['stuff'] = g
['stuff'].strip()
1414 for k
in all_config
:
1416 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1418 guide
= 'Detailed explanation can be found at ' + \
1419 color_func(c
['TWEET']['link'])(
1420 'http://rainbowstream.readthedocs.org/en/latest/#config-explanation')
1422 # Print specific config
1423 elif len(g
['stuff'].split()) == 1:
1424 if g
['stuff'] in all_config
:
1427 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1430 printNicely(red('No such config key.'))
1431 # Print specific config's default value
1432 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'default':
1433 key
= g
['stuff'].split()[0]
1435 value
= get_default_config(key
)
1436 line
= ' ' * 2 + green(key
) + ': ' + light_magenta(value
)
1440 printNicely(red('Just can not get the default.'))
1441 # Delete specific config key in config file
1442 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'drop':
1443 key
= g
['stuff'].split()[0]
1446 printNicely(green('Config key is dropped.'))
1449 printNicely(red('Just can not drop the key.'))
1450 # Set specific config
1451 elif len(g
['stuff'].split()) == 3 and g
['stuff'].split()[1] == '=':
1452 key
= g
['stuff'].split()[0]
1453 value
= g
['stuff'].split()[-1]
1454 if key
== 'THEME' and not validate_theme(value
):
1455 printNicely(red('Invalid theme\'s value.'))
1458 set_config(key
, value
)
1459 # Keys that needs to be apply immediately
1461 c
['THEME'] = reload_theme(value
, c
['THEME'])
1462 g
['decorated_name'] = lambda x
: color_func(
1463 c
['DECORATED_NAME'])('[' + x
+ ']: ')
1464 elif key
== 'PREFIX':
1465 g
['PREFIX'] = u2str(emojize(format_prefix(
1466 listname
=g
['listname'],
1467 keyword
=g
['keyword']
1470 printNicely(green('Updated successfully.'))
1473 printNicely(red('Just can not set the key.'))
1475 printNicely(light_magenta('Sorry I can\'s understand.'))
1478 def help_discover():
1483 # Discover the world
1485 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1486 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1487 'You can try ' + light_green('trend US') + ' or ' + \
1488 light_green('trend JP Tokyo') + '.\n'
1489 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1490 light_green('home 7') + ' will show 7 tweets.\n'
1492 light_green('notification') + ' will show your recent notification.\n'
1493 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1494 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1495 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1496 magenta('@mdo') + '.\n'
1497 usage
+= s
* 2 + light_green('view @mdo') + \
1498 ' will show ' + magenta('@mdo') + '\'s home.\n'
1499 usage
+= s
* 2 + light_green('s AKB48') + ' will search for "' + \
1500 light_yellow('AKB48') + '" and return 5 newest tweet. ' + \
1501 'Search can be performed with or without hashtag.\n'
1512 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1513 usage
+= s
* 2 + light_green('t oops ') + \
1514 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1516 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1517 light_yellow('[id=12]') + '.\n'
1519 light_green('quote 12 ') + ' will quote the tweet with ' + \
1520 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1521 'the quote will be canceled.\n'
1523 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1524 light_yellow('[id=12]') + '.\n'
1525 usage
+= s
* 2 + light_green('conversation 12') + ' will show the chain of ' + \
1526 'replies prior to the tweet with ' + light_yellow('[id=12]') + '.\n'
1527 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1528 light_yellow('oops') + '" to the owner of the tweet with ' + \
1529 light_yellow('[id=12]') + '.\n'
1530 usage
+= s
* 2 + light_green('repall 12 oops') + ' will reply "' + \
1531 light_yellow('oops') + '" to all people in the tweet with ' + \
1532 light_yellow('[id=12]') + '.\n'
1534 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1535 light_yellow('[id=12]') + '.\n'
1537 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1538 light_yellow('[id=12]') + '.\n'
1540 light_green('share 12 ') + ' will get the direct link of the tweet with ' + \
1541 light_yellow('[id=12]') + '.\n'
1543 light_green('del 12 ') + ' will delete tweet with ' + \
1544 light_yellow('[id=12]') + '.\n'
1545 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1546 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1547 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1548 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1552 def help_messages():
1559 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1560 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1561 light_green('inbox 7') + ' will show newest 7 messages.\n'
1562 usage
+= s
* 2 + light_green('thread 2') + ' will show full thread with ' + \
1563 light_yellow('[thread_id=2]') + '.\n'
1564 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1565 magenta('@dtvd88') + '.\n'
1566 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1567 light_yellow('[message_id=5]') + '.\n'
1571 def help_friends_and_followers():
1573 Friends and Followers
1576 # Follower and following
1578 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1580 light_green('ls fl') + \
1581 ' will list all followers (people who are following you).\n'
1583 light_green('ls fr') + \
1584 ' will list all friends (people who you are following).\n'
1585 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1586 magenta('@dtvd88') + '.\n'
1587 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1588 magenta('@dtvd88') + '.\n'
1589 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1590 magenta('@dtvd88') + '.\n'
1591 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1592 magenta('@dtvd88') + '.\n'
1593 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1594 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1595 magenta('@dtvd88') + '.\n'
1596 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1597 magenta('@dtvd88') + '.\n'
1598 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1599 magenta('@dtvd88') + ' as a spam account.\n'
1610 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1611 usage
+= s
* 2 + light_green('list') + \
1612 ' will show all lists you are belong to.\n'
1613 usage
+= s
* 2 + light_green('list home') + \
1614 ' will show timeline of list. You will be asked for list\'s name.\n'
1615 usage
+= s
* 2 + light_green('list all_mem') + \
1616 ' will show list\'s all members.\n'
1617 usage
+= s
* 2 + light_green('list all_sub') + \
1618 ' will show list\'s all subscribers.\n'
1619 usage
+= s
* 2 + light_green('list add') + \
1620 ' will add specific person to a list owned by you.' + \
1621 ' You will be asked for list\'s name and person\'s name.\n'
1622 usage
+= s
* 2 + light_green('list rm') + \
1623 ' will remove specific person from a list owned by you.' + \
1624 ' You will be asked for list\'s name and person\'s name.\n'
1625 usage
+= s
* 2 + light_green('list sub') + \
1626 ' will subscribe you to a specific list.\n'
1627 usage
+= s
* 2 + light_green('list unsub') + \
1628 ' will unsubscribe you from a specific list.\n'
1629 usage
+= s
* 2 + light_green('list own') + \
1630 ' will show all list owned by you.\n'
1631 usage
+= s
* 2 + light_green('list new') + \
1632 ' will create a new list.\n'
1633 usage
+= s
* 2 + light_green('list update') + \
1634 ' will update a list owned by you.\n'
1635 usage
+= s
* 2 + light_green('list del') + \
1636 ' will delete a list owned by you.\n'
1647 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1648 usage
+= s
* 2 + light_green('switch public #AKB') + \
1649 ' will switch to public stream and follow "' + \
1650 light_yellow('AKB') + '" keyword.\n'
1651 usage
+= s
* 2 + light_green('switch mine') + \
1652 ' will switch to your personal stream.\n'
1653 usage
+= s
* 2 + light_green('switch mine -f ') + \
1654 ' will prompt to enter the filter.\n'
1655 usage
+= s
* 3 + light_yellow('Only nicks') + \
1656 ' filter will decide nicks will be INCLUDE ONLY.\n'
1657 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1658 ' filter will decide nicks will be EXCLUDE.\n'
1659 usage
+= s
* 2 + light_green('switch list') + \
1660 ' will switch to a Twitter list\'s stream. You will be asked for list name\n'
1669 h
, w
= os
.popen('stty size', 'r').read().split()
1672 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1673 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1674 usage
+= s
+ 'You are ' + \
1675 light_yellow('already') + ' on your personal stream.\n'
1676 usage
+= s
+ 'Any update from Twitter will show up ' + \
1677 light_yellow('immediately') + '.\n'
1678 usage
+= s
+ 'In addition, following commands are available right now:\n'
1679 # Twitter help section
1681 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1682 usage
+= s
* 2 + light_green('h discover') + \
1683 ' will show help for discover commands.\n'
1684 usage
+= s
* 2 + light_green('h tweets') + \
1685 ' will show help for tweets commands.\n'
1686 usage
+= s
* 2 + light_green('h messages') + \
1687 ' will show help for messages commands.\n'
1688 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1689 ' will show help for friends and followers commands.\n'
1690 usage
+= s
* 2 + light_green('h list') + \
1691 ' will show help for list commands.\n'
1692 usage
+= s
* 2 + light_green('h stream') + \
1693 ' will show help for stream commands.\n'
1696 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1697 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1698 'will be evaluate by Python interpreter.\n'
1699 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1700 ' for current month.\n'
1703 usage
+= s
+ grey(u
'\u266A' + ' Config \n')
1704 usage
+= s
* 2 + light_green('theme') + ' will list available theme. ' + \
1705 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1706 ' theme immediately.\n'
1707 usage
+= s
* 2 + light_green('config') + ' will list all config.\n'
1709 light_green('config ASCII_ART') + ' will output current value of ' +\
1710 light_yellow('ASCII_ART') + ' config key.\n'
1712 light_green('config TREND_MAX default') + ' will output default value of ' + \
1713 light_yellow('TREND_MAX') + ' config key.\n'
1715 light_green('config CUSTOM_CONFIG drop') + ' will drop ' + \
1716 light_yellow('CUSTOM_CONFIG') + ' config key.\n'
1718 light_green('config IMAGE_ON_TERM = true') + ' will set value of ' + \
1719 light_yellow('IMAGE_ON_TERM') + ' config key to ' + \
1720 light_yellow('True') + '.\n'
1723 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1724 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1725 usage
+= s
* 2 + light_green('p') + ' will pause the stream.\n'
1726 usage
+= s
* 2 + light_green('r') + ' will unpause the stream.\n'
1727 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1728 usage
+= s
* 2 + light_green('v') + ' will show version info.\n'
1729 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1732 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1733 usage
+= s
+ 'Have fun and hang tight! \n'
1736 'discover': help_discover
,
1737 'tweets': help_tweets
,
1738 'messages': help_messages
,
1739 'friends_and_followers': help_friends_and_followers
,
1741 'stream': help_stream
,
1746 lambda: printNicely(red('No such command.'))
1754 Pause stream display
1757 printNicely(green('Stream is paused'))
1765 printNicely(green('Stream is running back now'))
1781 printNicely(green('See you next time :)'))
1789 Reset prefix of line
1792 if c
.get('USER_JSON_ERROR'):
1793 printNicely(red('Your ~/.rainbow_config.json is messed up:'))
1794 printNicely(red('>>> ' + c
['USER_JSON_ERROR']))
1796 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1799 printNicely(str(eval(g
['cmd'])))
1852 # Handle function set
1905 return dict(zip(cmdset
, funcset
)).get(cmd
, reset
)
1910 Listen to user's input
1915 ['public', 'mine', 'list'], # switch
1934 ['image'], # show image
1936 ['fl', 'fr'], # list
1938 [i
for i
in g
['message_threads']], # sent
1963 [key
for key
in dict(get_all_config())], # config
1964 g
['themes'], # theme
1969 'friends_and_followers',
1980 init_interactive_shell(d
)
1987 # Only use PREFIX as a string with raw_input
1988 line
= raw_input(g
['decorated_name'](g
['PREFIX']))
1991 # Save cmd to compare with readline buffer
1992 g
['cmd'] = line
.strip()
1993 # Get short cmd to pass to handle function
1995 cmd
= line
.split()[0]
1998 # Lock the semaphore
2000 # Save cmd to global variable and call process
2001 g
['stuff'] = ' '.join(line
.split()[1:])
2002 # Process the command
2005 if cmd
in ['switch', 't', 'rt', 'rep']:
2009 # Release the semaphore lock
2015 printNicely(red('OMG something is wrong with Twitter right now.'))
2018 def reconn_notice():
2020 Notice when Hangup or Timeout
2022 guide
= light_magenta('You can use ') + \
2023 light_green('switch') + \
2024 light_magenta(' command to return to your stream.\n')
2025 guide
+= light_magenta('Type ') + \
2026 light_green('h stream') + \
2027 light_magenta(' for more details.')
2029 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2033 def stream(domain
, args
, name
='Rainbow Stream'):
2039 c
['USER_DOMAIN']: name
,
2040 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
2041 c
['SITE_DOMAIN']: name
,
2044 ascii_art(art_dict
[domain
])
2045 # These arguments are optional:
2047 timeout
=0.5, # To check g['stream_stop'] after each 0.5 s
2049 heartbeat_timeout
=c
['HEARTBEAT_TIMEOUT'] * 60)
2052 if args
.track_keywords
:
2053 query_args
['track'] = args
.track_keywords
2055 stream
= TwitterStream(
2060 if domain
== c
['USER_DOMAIN']:
2061 tweet_iter
= stream
.user(**query_args
)
2062 elif domain
== c
['SITE_DOMAIN']:
2063 tweet_iter
= stream
.site(**query_args
)
2065 if args
.track_keywords
:
2066 tweet_iter
= stream
.statuses
.filter(**query_args
)
2068 tweet_iter
= stream
.statuses
.sample()
2069 # Block new stream until other one exits
2070 StreamLock
.acquire()
2071 g
['stream_stop'] = False
2072 last_tweet_time
= time
.time()
2073 for tweet
in tweet_iter
:
2075 printNicely('-- None --')
2076 elif tweet
is Timeout
:
2077 # Because the stream check for each 0.3s
2078 # so we shouldn't output anything here
2079 if(g
['stream_stop']):
2080 StreamLock
.release()
2082 elif tweet
is HeartbeatTimeout
:
2083 printNicely('-- Heartbeat Timeout --')
2085 StreamLock
.release()
2087 elif tweet
is Hangup
:
2088 printNicely('-- Hangup --')
2090 StreamLock
.release()
2092 elif tweet
.get('text'):
2093 # Slow down the stream by STREAM_DELAY config key
2094 if time
.time() - last_tweet_time
< c
['STREAM_DELAY']:
2096 last_tweet_time
= time
.time()
2097 # Check the semaphore pause and lock (stream process only)
2105 keyword
=args
.track_keywords
,
2110 # Current readline buffer
2111 current_buffer
= readline
.get_line_buffer().strip()
2112 # There is an unexpected behaviour in MacOSX readline + Python 2:
2113 # after completely delete a word after typing it,
2114 # somehow readline buffer still contains
2115 # the 1st character of that word
2116 if current_buffer
and g
['cmd'] != current_buffer
:
2118 g
['decorated_name'](g
['PREFIX']) + current_buffer
)
2120 elif not c
['HIDE_PROMPT']:
2121 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2123 elif tweet
.get('direct_message'):
2124 # Check the semaphore pause and lock (stream process only)
2129 print_message(tweet
['direct_message'])
2130 elif tweet
.get('event'):
2131 c
['events'].append(tweet
)
2133 except TwitterHTTPError
as e
:
2136 magenta('We have connection problem with twitter stream API right now :('))
2137 detail_twitter_error(e
)
2138 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2140 except (URLError
, ConnectionResetError
):
2142 magenta('There seems to be a connection problem.'))
2152 args
= parse_arguments()
2156 # Twitter API connection problem
2157 except TwitterHTTPError
as e
:
2160 magenta('We have connection problem with twitter REST API right now :('))
2161 detail_twitter_error(e
)
2164 # Proxy connection problem
2165 except (socks
.ProxyConnectionError
, URLError
):
2167 magenta('There seems to be a connection problem.'))
2169 magenta('You might want to check your proxy settings (host, port and type)!'))
2173 # Spawn stream thread
2174 target
= args
.stream
.split()[0]
2175 if target
== 'public':
2177 keyword
= args
.stream
.split()[1]
2178 if keyword
[0] == '#':
2179 keyword
= keyword
[1:]
2180 args
.track_keywords
= keyword
2181 # Set the variable to tracked keyword
2182 g
['keyword'] = keyword
2184 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
2186 th
= threading
.Thread(
2194 printNicely(red('Public requires a keyword! Loading your personal stream.'))
2196 th
= threading
.Thread(
2201 g
['original_name']))
2204 elif target
== "list":
2206 owner
, slug
= check_slug(args
.stream
.split()[1])
2207 # Force python 2 not redraw readline buffer
2208 listname
= '/'.join([owner
, slug
])
2209 # Set the listname variable
2210 # and reset tracked keyword
2211 g
['listname'] = listname
2213 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
2214 listname
=g
['listname']
2216 printNicely(light_yellow('getting list members ...'))
2218 t
= Twitter(auth
=authen())
2221 while next_cursor
!= 0:
2222 m
= t
.lists
.members(
2224 owner_screen_name
=owner
,
2226 include_entities
=False)
2227 for u
in m
['users']:
2228 members
.append('@' + u
['screen_name'])
2229 next_cursor
= m
['next_cursor']
2230 printNicely(light_yellow('... done.'))
2231 # Build thread filter array
2232 args
.filter = members
2234 g
['stream_stop'] = True
2236 th
= threading
.Thread(
2246 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
2248 printNicely(red('List requieres a correct name of a list! Loading your personal stream.'))
2250 th
= threading
.Thread(
2255 g
['original_name']))
2258 elif target
== "mine":
2260 th
= threading
.Thread(
2265 g
['original_name']))
2269 printNicely(red('Wrong -s/--stream argument given. Loading your personal stream.'))
2271 th
= threading
.Thread(
2276 g
['original_name']))
2280 # Start listen process