15 from io
import BytesIO
16 from twitter
.stream
import TwitterStream
, Timeout
, HeartbeatTimeout
, Hangup
17 from twitter
.api
import *
18 from twitter
.oauth
import OAuth
, read_token_file
19 from twitter
.oauth_dance
import oauth_dance
20 from twitter
.util
import printNicely
25 from .consumer
import *
26 from .interactive
import *
27 from .c_image
import *
28 from .py3patch
import *
36 StreamLock
= threading
.Lock()
39 def parse_arguments():
43 parser
= argparse
.ArgumentParser(description
=__doc__
or "")
48 help='Default stream after program start. (Default: mine)')
52 help='Timeout for the stream (seconds).')
56 help='Search the stream for specific text.')
60 help='Filter specific screen_name.')
64 help='Ignore specific screen_name.')
69 help='Display all image on terminal.')
73 help='Use HTTP/SOCKS proxy for network connections.')
78 help='HTTP/SOCKS proxy port (Default: 8080).')
83 help='Proxy type (HTTP, SOCKS4, SOCKS5; Default: SOCKS5).')
84 return parser
.parse_args()
87 def proxy_connect(args
):
89 Connect to specified proxy
92 # Setup proxy by monkeypatching the standard lib
93 if args
.proxy_type
.lower() == "socks5" or not args
.proxy_type
:
94 socks
.set_default_proxy(
95 socks
.SOCKS5
, args
.proxy_host
,
97 elif args
.proxy_type
.lower() == "http":
98 socks
.set_default_proxy(
99 socks
.HTTP
, args
.proxy_host
,
100 int(args
.proxy_port
))
101 elif args
.proxy_type
.lower() == "socks4":
102 socks
.set_default_proxy(
103 socks
.SOCKS4
, args
.proxy_host
,
104 int(args
.proxy_port
))
107 magenta('Sorry, wrong proxy type specified! Aborting...'))
109 socket
.socket
= socks
.socksocket
114 Authenticate with Twitter OAuth
116 # When using rainbow stream you must authorize.
117 twitter_credential
= os
.environ
.get(
121 '')) + os
.sep
+ '.rainbow_oauth'
122 if not os
.path
.exists(twitter_credential
):
123 oauth_dance('Rainbow Stream',
127 oauth_token
, oauth_token_secret
= read_token_file(twitter_credential
)
135 def build_mute_dict(dict_data
=False):
139 t
= Twitter(auth
=authen())
142 screen_name_list
= []
145 while next_cursor
!= 0:
146 list = t
.mutes
.users
.list(
147 screen_name
=g
['original_name'],
150 include_entities
=False,
152 screen_name_list
+= ['@' + u
['screen_name'] for u
in list['users']]
153 name_list
+= [u
['name'] for u
in list['users']]
154 next_cursor
= list['next_cursor']
155 # Return dict or list
157 return dict(zip(screen_name_list
, name_list
))
159 return screen_name_list
164 Save traceback when run in debug mode
167 g
['traceback'].append(traceback
.format_exc())
170 def upgrade_center():
172 Check latest and notify to upgrade
175 current
= pkg_resources
.get_distribution('rainbowstream').version
176 url
= 'https://raw.githubusercontent.com/DTVD/rainbowstream/master/setup.py'
177 readme
= requests
.get(url
).text
178 latest
= readme
.split('version = \'')[1].split('\'')[0]
179 if current
!= latest
:
180 notice
= light_magenta('RainbowStream latest version is ')
181 notice
+= light_green(latest
)
182 notice
+= light_magenta(' while your current version is ')
183 notice
+= light_yellow(current
) + '\n'
184 notice
+= light_magenta('You should upgrade with ')
185 notice
+= light_green('pip install -U rainbowstream')
188 notice
= light_yellow('You are running latest version (')
189 notice
+= light_green(current
)
190 notice
+= light_yellow(')')
201 ctrl_c_handler
= lambda signum
, frame
: quit()
202 signal
.signal(signal
.SIGINT
, ctrl_c_handler
)
206 t
= Twitter(auth
=authen())
207 credential
= t
.account
.verify_credentials()
208 screen_name
= '@' + credential
['screen_name']
209 name
= credential
['name']
210 c
['original_name'] = g
['original_name'] = screen_name
[1:]
211 g
['listname'] = g
['keyword'] = ''
212 g
['PREFIX'] = u2str(emojize(format_prefix()))
213 g
['full_name'] = name
214 g
['decorated_name'] = lambda x
: color_func(
215 c
['DECORATED_NAME'])('[' + x
+ ']: ', rl
=True)
217 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
218 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
221 g
['message_threads'] = {}
224 # Debug option default = True
231 # Init tweet dict and message dict
233 c
['message_dict'] = []
235 c
['IMAGE_ON_TERM'] = args
.image_on_term
236 set_config('IMAGE_ON_TERM', str(c
['IMAGE_ON_TERM']))
237 # Check type of ONLY_LIST and IGNORE_LIST
238 if not isinstance(c
['ONLY_LIST'], list):
239 printNicely(red('ONLY_LIST is not a valid list value.'))
241 if not isinstance(c
['IGNORE_LIST'], list):
242 printNicely(red('IGNORE_LIST is not a valid list value.'))
243 c
['IGNORE_LIST'] = []
245 c
['IGNORE_LIST'] += build_mute_dict()
252 t
= Twitter(auth
=authen())
253 # Get country and town
255 country
= g
['stuff'].split()[0]
259 town
= g
['stuff'].split()[1]
262 avail
= t
.trends
.available()
265 trends
= t
.trends
.place(_id
=1)[0]['trends']
268 for location
in avail
:
269 # Search for country and Town
271 if location
['countryCode'] == country \
272 and location
['placeType']['name'] == 'Town' \
273 and location
['name'] == town
:
274 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
276 # Search for country only
278 if location
['countryCode'] == country \
279 and location
['placeType']['name'] == 'Country':
280 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
288 t
= Twitter(auth
=authen())
289 num
= c
['HOME_TWEET_NUM']
290 if g
['stuff'].isdigit():
291 num
= int(g
['stuff'])
292 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
302 for e
in c
['events']:
306 printNicely(magenta('Nothing at this time.'))
313 t
= Twitter(auth
=authen())
314 num
= c
['HOME_TWEET_NUM']
315 if g
['stuff'].isdigit():
316 num
= int(g
['stuff'])
317 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
324 Show profile of a specific user
326 t
= Twitter(auth
=authen())
327 screen_name
= g
['stuff'].split()[0]
328 if screen_name
.startswith('@'):
331 screen_name
=screen_name
[1:],
332 include_entities
=False)
336 printNicely(red('No user.'))
338 printNicely(red('A name should begin with a \'@\''))
345 t
= Twitter(auth
=authen())
346 user
= g
['stuff'].split()[0]
349 num
= int(g
['stuff'].split()[1])
351 num
= c
['HOME_TWEET_NUM']
352 for tweet
in reversed(
353 t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
357 printNicely(red('A name should begin with a \'@\''))
364 t
= Twitter(auth
=authen())
366 query
= g
['stuff'].strip()
367 type = c
['SEARCH_TYPE']
368 if type not in ['mixed', 'recent', 'popular']:
370 max_record
= c
['SEARCH_MAX_RECORD']
371 count
= min(max_record
, 100)
373 rel
= t
.search
.tweets(
380 printNicely('Newest tweets:')
381 for i
in reversed(xrange(count
)):
382 draw(t
=rel
[i
], keyword
=query
)
385 printNicely(magenta('I\'m afraid there is no result'))
392 t
= Twitter(auth
=authen())
393 t
.statuses
.update(status
=g
['stuff'])
400 t
= Twitter(auth
=authen())
402 id = int(g
['stuff'].split()[0])
404 printNicely(red('Sorry I can\'t understand.'))
406 tid
= c
['tweet_dict'][id]
407 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
415 t
= Twitter(auth
=authen())
417 id = int(g
['stuff'].split()[0])
419 printNicely(red('Sorry I can\'t understand.'))
421 tid
= c
['tweet_dict'][id]
422 tweet
= t
.statuses
.show(id=tid
)
424 formater
= format_quote(tweet
)
428 prefix
= light_magenta('Compose your ', rl
=True) + \
429 light_green('#comment: ', rl
=True)
430 comment
= raw_input(prefix
)
432 quote
= comment
.join(formater
.split('#comment'))
433 t
.statuses
.update(status
=quote
)
435 printNicely(light_magenta('No text added.'))
442 t
= Twitter(auth
=authen())
445 id = int(g
['stuff'].split()[0])
447 printNicely(red('Sorry I can\'t understand.'))
449 tid
= c
['tweet_dict'][id]
450 # Get display num if exist
452 num
= int(g
['stuff'].split()[1])
454 num
= c
['RETWEETS_SHOW_NUM']
455 # Get result and display
456 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
458 printNicely(magenta('This tweet has no retweet.'))
460 for tweet
in reversed(rt_ary
):
469 t
= Twitter(auth
=authen())
471 id = int(g
['stuff'].split()[0])
473 printNicely(red('Sorry I can\'t understand.'))
475 tid
= c
['tweet_dict'][id]
476 tweet
= t
.statuses
.show(id=tid
)
477 limit
= c
['CONVERSATION_MAX']
479 thread_ref
.append(tweet
)
480 prev_tid
= tweet
['in_reply_to_status_id']
481 while prev_tid
and limit
:
483 tweet
= t
.statuses
.show(id=prev_tid
)
484 prev_tid
= tweet
['in_reply_to_status_id']
485 thread_ref
.append(tweet
)
487 for tweet
in reversed(thread_ref
):
496 t
= Twitter(auth
=authen())
498 id = int(g
['stuff'].split()[0])
500 printNicely(red('Sorry I can\'t understand.'))
502 tid
= c
['tweet_dict'][id]
503 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
504 status
= ' '.join(g
['stuff'].split()[1:])
505 status
= '@' + user
+ ' ' + str2u(status
)
506 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
513 t
= Twitter(auth
=authen())
515 id = int(g
['stuff'].split()[0])
517 printNicely(red('Sorry I can\'t understand.'))
519 tid
= c
['tweet_dict'][id]
520 original_tweet
= t
.statuses
.show(id=tid
)
521 text
= original_tweet
['text']
522 owner
= '@' + original_tweet
['user']['screen_name']
523 nick_ary
= ['@' + re
.sub('[\W_]', '', w
)
524 for w
in text
.split() if w
.startswith('@')] + [owner
]
525 status
= ' '.join(g
['stuff'].split()[1:])
526 status
= ' '.join(nick_ary
) + ' ' + str2u(status
)
527 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
534 t
= Twitter(auth
=authen())
536 id = int(g
['stuff'].split()[0])
538 printNicely(red('Sorry I can\'t understand.'))
540 tid
= c
['tweet_dict'][id]
541 t
.favorites
.create(_id
=tid
, include_entities
=False)
542 printNicely(green('Favorited.'))
543 draw(t
.statuses
.show(id=tid
))
551 t
= Twitter(auth
=authen())
553 id = int(g
['stuff'].split()[0])
555 printNicely(red('Sorry I can\'t understand.'))
557 tid
= c
['tweet_dict'][id]
558 t
.favorites
.destroy(_id
=tid
)
559 printNicely(green('Okay it\'s unfavorited.'))
560 draw(t
.statuses
.show(id=tid
))
566 Copy url of a tweet to clipboard
568 t
= Twitter(auth
=authen())
570 id = int(g
['stuff'].split()[0])
571 tid
= c
['tweet_dict'][id]
573 printNicely(red('Tweet id is not valid.'))
575 tweet
= t
.statuses
.show(id=tid
)
576 url
= 'https://twitter.com/' + \
577 tweet
['user']['screen_name'] + '/status/' + str(tid
)
579 if platform
.system().lower() == 'darwin':
580 os
.system("echo '%s' | pbcopy" % url
)
581 printNicely(green('Copied tweet\'s url to clipboard.'))
583 printNicely('Direct link: ' + yellow(url
))
590 t
= Twitter(auth
=authen())
592 id = int(g
['stuff'].split()[0])
594 printNicely(red('Sorry I can\'t understand.'))
596 tid
= c
['tweet_dict'][id]
597 t
.statuses
.destroy(id=tid
)
598 printNicely(green('Okay it\'s gone.'))
605 t
= Twitter(auth
=authen())
607 target
= g
['stuff'].split()[0]
608 if target
!= 'image':
610 id = int(g
['stuff'].split()[1])
611 tid
= c
['tweet_dict'][id]
612 tweet
= t
.statuses
.show(id=tid
)
613 media
= tweet
['entities']['media']
615 res
= requests
.get(m
['media_url'])
616 img
= Image
.open(BytesIO(res
.content
))
620 printNicely(red('Sorry I can\'t show this image.'))
627 t
= Twitter(auth
=authen())
629 if not g
['stuff'].isdigit():
631 tid
= c
['tweet_dict'][int(g
['stuff'])]
632 tweet
= t
.statuses
.show(id=tid
)
633 link_prefix
= ('http://', 'https://')
634 link_ary
= [u
for u
in tweet
['text'].split()
635 if u
.startswith(link_prefix
)]
637 printNicely(light_magenta('No url here @.@!'))
639 for link
in link_ary
:
640 webbrowser
.open(link
)
643 printNicely(red('Sorry I can\'t open url in this tweet.'))
650 t
= Twitter(auth
=authen())
651 num
= c
['MESSAGES_DISPLAY']
652 if g
['stuff'].isdigit():
658 inbox
= inbox
+ t
.direct_messages(
661 include_entities
=False,
666 inbox
= inbox
+ t
.direct_messages(
669 include_entities
=False,
673 num
= c
['MESSAGES_DISPLAY']
674 if g
['stuff'].isdigit():
679 sent
= sent
+ t
.direct_messages
.sent(
682 include_entities
=False,
687 sent
= sent
+ t
.direct_messages
.sent(
690 include_entities
=False,
695 uniq_inbox
= list(set(
696 [(m
['sender_screen_name'], m
['sender']['name']) for m
in inbox
]
698 uniq_sent
= list(set(
699 [(m
['recipient_screen_name'], m
['recipient']['name']) for m
in sent
]
701 for partner
in uniq_inbox
:
702 inbox_ary
= [m
for m
in inbox
if m
['sender_screen_name'] == partner
[0]]
704 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
705 d
[partner
] = inbox_ary
+ sent_ary
706 for partner
in uniq_sent
:
709 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
710 g
['message_threads'] = print_threads(d
)
715 View a thread of message
718 thread_id
= int(g
['stuff'])
720 g
['message_threads'][thread_id
],
725 printNicely(red('No such thread.'))
730 Send a direct message
732 t
= Twitter(auth
=authen())
734 user
= g
['stuff'].split()[0]
735 if user
[0].startswith('@'):
736 content
= ' '.join(g
['stuff'].split()[1:])
737 t
.direct_messages
.new(
738 screen_name
=user
[1:],
741 printNicely(green('Message sent.'))
743 printNicely(red('A name should begin with a \'@\''))
746 printNicely(red('Sorry I can\'t understand.'))
753 t
= Twitter(auth
=authen())
755 id = int(g
['stuff'].split()[0])
757 printNicely(red('Sorry I can\'t understand.'))
758 mid
= c
['message_dict'][id]
759 t
.direct_messages
.destroy(id=mid
)
760 printNicely(green('Message deleted.'))
765 List friends for followers
767 t
= Twitter(auth
=authen())
770 name
= g
['stuff'].split()[1]
771 if name
.startswith('@'):
774 printNicely(red('A name should begin with a \'@\''))
775 raise Exception('Invalid name')
777 name
= g
['original_name']
778 # Get list followers or friends
780 target
= g
['stuff'].split()[0]
782 printNicely(red('Omg some syntax is wrong.'))
784 d
= {'fl': 'followers', 'fr': 'friends'}
788 while next_cursor
!= 0:
789 list = getattr(t
, d
[target
]).list(
793 include_entities
=False,
795 for u
in list['users']:
796 rel
[u
['name']] = '@' + u
['screen_name']
797 next_cursor
= list['next_cursor']
799 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
801 user
= ' ' + cycle_color(name
)
802 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
810 t
= Twitter(auth
=authen())
811 screen_name
= g
['stuff'].split()[0]
812 if screen_name
.startswith('@'):
813 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
814 printNicely(green('You are following ' + screen_name
+ ' now!'))
816 printNicely(red('A name should begin with a \'@\''))
823 t
= Twitter(auth
=authen())
824 screen_name
= g
['stuff'].split()[0]
825 if screen_name
.startswith('@'):
826 t
.friendships
.destroy(
827 screen_name
=screen_name
[1:],
828 include_entities
=False)
829 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
831 printNicely(red('A name should begin with a \'@\''))
838 t
= Twitter(auth
=authen())
840 screen_name
= g
['stuff'].split()[0]
842 printNicely(red('A name should be specified. '))
844 if screen_name
.startswith('@'):
846 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
847 if isinstance(rel
, dict):
848 printNicely(green(screen_name
+ ' is muted.'))
849 c
['IGNORE_LIST'] += [unc(screen_name
)]
850 c
['IGNORE_LIST'] = list(set(c
['IGNORE_LIST']))
852 printNicely(red(rel
))
855 printNicely(red('Something is wrong, can not mute now :('))
857 printNicely(red('A name should begin with a \'@\''))
864 t
= Twitter(auth
=authen())
866 screen_name
= g
['stuff'].split()[0]
868 printNicely(red('A name should be specified. '))
870 if screen_name
.startswith('@'):
872 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
873 if isinstance(rel
, dict):
874 printNicely(green(screen_name
+ ' is unmuted.'))
875 c
['IGNORE_LIST'].remove(screen_name
)
877 printNicely(red(rel
))
879 printNicely(red('Maybe you are not muting this person ?'))
881 printNicely(red('A name should begin with a \'@\''))
888 # Get dict of muting users
889 md
= build_mute_dict(dict_data
=True)
890 printNicely('All: ' + str(len(md
)) + ' people.')
892 user
= ' ' + cycle_color(md
[name
])
893 user
+= color_func(c
['TWEET']['nick'])(' ' + name
+ ' ')
895 # Update from Twitter
896 c
['IGNORE_LIST'] = [n
for n
in md
]
903 t
= Twitter(auth
=authen())
904 screen_name
= g
['stuff'].split()[0]
905 if screen_name
.startswith('@'):
907 screen_name
=screen_name
[1:],
908 include_entities
=False,
910 printNicely(green('You blocked ' + screen_name
+ '.'))
912 printNicely(red('A name should begin with a \'@\''))
919 t
= Twitter(auth
=authen())
920 screen_name
= g
['stuff'].split()[0]
921 if screen_name
.startswith('@'):
923 screen_name
=screen_name
[1:],
924 include_entities
=False,
926 printNicely(green('Unblock ' + screen_name
+ ' success!'))
928 printNicely(red('A name should begin with a \'@\''))
933 Report a user as a spam account
935 t
= Twitter(auth
=authen())
936 screen_name
= g
['stuff'].split()[0]
937 if screen_name
.startswith('@'):
939 screen_name
=screen_name
[1:])
940 printNicely(green('You reported ' + screen_name
+ '.'))
942 printNicely(red('Sorry I can\'t understand.'))
950 list_name
= raw_input(
951 light_magenta('Give me the list\'s name ("@owner/list_name"): ', rl
=True))
952 # Get list name and owner
954 owner
, slug
= list_name
.split('/')
955 if slug
.startswith('@'):
960 light_magenta('List name should follow "@owner/list_name" format.'))
961 raise Exception('Wrong list name')
963 def check_slug(list_name
):
967 # Get list name and owner
969 owner
, slug
= list_name
.split('/')
970 if slug
.startswith('@'):
975 light_magenta('List name should follow "@owner/list_name" format.'))
976 raise Exception('Wrong list name')
982 rel
= t
.lists
.list(screen_name
=g
['original_name'])
986 printNicely(light_magenta('You belong to no lists :)'))
993 owner
, slug
= get_slug()
994 res
= t
.lists
.statuses(
996 owner_screen_name
=owner
,
998 include_entities
=False)
999 for tweet
in reversed(res
):
1004 def list_members(t
):
1008 owner
, slug
= get_slug()
1012 while next_cursor
!= 0:
1013 m
= t
.lists
.members(
1015 owner_screen_name
=owner
,
1017 include_entities
=False)
1018 for u
in m
['users']:
1019 rel
[u
['name']] = '@' + u
['screen_name']
1020 next_cursor
= m
['next_cursor']
1021 printNicely('All: ' + str(len(rel
)) + ' members.')
1023 user
= ' ' + cycle_color(name
)
1024 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1028 def list_subscribers(t
):
1032 owner
, slug
= get_slug()
1036 while next_cursor
!= 0:
1037 m
= t
.lists
.subscribers(
1039 owner_screen_name
=owner
,
1041 include_entities
=False)
1042 for u
in m
['users']:
1043 rel
[u
['name']] = '@' + u
['screen_name']
1044 next_cursor
= m
['next_cursor']
1045 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
1047 user
= ' ' + cycle_color(name
)
1048 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1054 Add specific user to a list
1056 owner
, slug
= get_slug()
1058 user_name
= raw_input(
1060 'Give me name of the newbie: ',
1062 if user_name
.startswith('@'):
1063 user_name
= user_name
[1:]
1065 t
.lists
.members
.create(
1067 owner_screen_name
=owner
,
1068 screen_name
=user_name
)
1069 printNicely(green('Added.'))
1072 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
1077 Remove specific user from a list
1079 owner
, slug
= get_slug()
1081 user_name
= raw_input(
1083 'Give me name of the unlucky one: ',
1085 if user_name
.startswith('@'):
1086 user_name
= user_name
[1:]
1088 t
.lists
.members
.destroy(
1090 owner_screen_name
=owner
,
1091 screen_name
=user_name
)
1092 printNicely(green('Gone.'))
1095 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
1098 def list_subscribe(t
):
1102 owner
, slug
= get_slug()
1105 t
.lists
.subscribers
.create(
1107 owner_screen_name
=owner
)
1108 printNicely(green('Done.'))
1112 light_magenta('I\'m sorry you can not subscribe to this list.'))
1115 def list_unsubscribe(t
):
1119 owner
, slug
= get_slug()
1122 t
.lists
.subscribers
.destroy(
1124 owner_screen_name
=owner
)
1125 printNicely(green('Done.'))
1129 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
1138 while next_cursor
!= 0:
1139 res
= t
.lists
.ownerships(
1140 screen_name
=g
['original_name'],
1143 next_cursor
= res
['next_cursor']
1147 printNicely(light_magenta('You own no lists :)'))
1154 name
= raw_input(light_magenta('New list\'s name: ', rl
=True))
1157 'New list\'s mode (public/private): ',
1159 description
= raw_input(
1161 'New list\'s description: ',
1167 description
=description
)
1168 printNicely(green(name
+ ' list is created.'))
1171 printNicely(red('Oops something is wrong with Twitter :('))
1180 'Your list that you want to update: ',
1184 'Update name (leave blank to unchange): ',
1186 mode
= raw_input(light_magenta('Update mode (public/private): ', rl
=True))
1187 description
= raw_input(light_magenta('Update description: ', rl
=True))
1191 slug
='-'.join(slug
.split()),
1192 owner_screen_name
=g
['original_name'],
1195 description
=description
)
1199 owner_screen_name
=g
['original_name'],
1201 description
=description
)
1202 printNicely(green(slug
+ ' list is updated.'))
1205 printNicely(red('Oops something is wrong with Twitter :('))
1214 'Your list that you want to delete: ',
1218 slug
='-'.join(slug
.split()),
1219 owner_screen_name
=g
['original_name'])
1220 printNicely(green(slug
+ ' list is deleted.'))
1223 printNicely(red('Oops something is wrong with Twitter :('))
1230 t
= Twitter(auth
=authen())
1231 # List all lists or base on action
1233 g
['list_action'] = g
['stuff'].split()[0]
1240 'all_mem': list_members
,
1241 'all_sub': list_subscribers
,
1244 'sub': list_subscribe
,
1245 'unsub': list_unsubscribe
,
1248 'update': list_update
,
1252 return action_ary
[g
['list_action']](t
)
1254 printNicely(red('Please try again.'))
1262 target
= g
['stuff'].split()[0]
1264 args
= parse_arguments()
1266 if g
['stuff'].split()[-1] == '-f':
1267 guide
= 'To ignore an option, just hit Enter key.'
1268 printNicely(light_magenta(guide
))
1269 only
= raw_input('Only nicks [Ex: @xxx,@yy]: ')
1270 ignore
= raw_input('Ignore nicks [Ex: @xxx,@yy]: ')
1271 args
.filter = filter(None, only
.split(','))
1272 args
.ignore
= filter(None, ignore
.split(','))
1274 printNicely(red('Sorry, wrong format.'))
1277 if target
== 'public':
1278 keyword
= g
['stuff'].split()[1]
1279 if keyword
[0] == '#':
1280 keyword
= keyword
[1:]
1282 g
['stream_stop'] = True
1283 args
.track_keywords
= keyword
1284 # Set the variable to tracked keyword
1285 # and reset the listname
1286 g
['keyword'] = keyword
1289 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
1291 th
= threading
.Thread(
1299 elif target
== 'mine':
1301 g
['stream_stop'] = True
1302 # Reset the tracked keyword and listname
1303 g
['keyword'] = g
['listname'] = ''
1305 g
['PREFIX'] = u2str(emojize(format_prefix()))
1307 th
= threading
.Thread(
1312 g
['original_name']))
1315 # Stream base on list
1316 elif target
== 'list':
1317 owner
, slug
= get_slug()
1318 # Force python 2 not redraw readline buffer
1319 listname
= '/'.join([owner
, slug
])
1320 # Set the listname variable
1321 # and reset tracked keyword
1322 g
['listname'] = listname
1324 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
1325 listname
=g
['listname']
1327 printNicely(light_yellow('getting list members ...'))
1329 t
= Twitter(auth
=authen())
1332 while next_cursor
!= 0:
1333 m
= t
.lists
.members(
1335 owner_screen_name
=owner
,
1337 include_entities
=False)
1338 for u
in m
['users']:
1339 members
.append('@' + u
['screen_name'])
1340 next_cursor
= m
['next_cursor']
1341 printNicely(light_yellow('... done.'))
1342 # Build thread filter array
1343 args
.filter = members
1345 g
['stream_stop'] = True
1347 th
= threading
.Thread(
1357 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
1359 printNicely(red('Ignore: ' + str(len(args
.ignore
)) + ' people.'))
1363 printNicely(red('Sorry I can\'t understand.'))
1368 Unix's command `cal`
1371 rel
= os
.popen('cal').read().split('\n')
1374 show_calendar(month
, date
, rel
)
1379 List and change theme
1383 for theme
in g
['themes']:
1384 line
= light_magenta(theme
)
1385 if c
['THEME'] == theme
:
1386 line
= ' ' * 2 + light_yellow('* ') + line
1388 line
= ' ' * 4 + line
1394 c
['THEME'] = reload_theme(g
['stuff'], c
['THEME'])
1395 # Redefine decorated_name
1396 g
['decorated_name'] = lambda x
: color_func(
1397 c
['DECORATED_NAME'])(
1399 printNicely(green('Theme changed.'))
1401 printNicely(red('No such theme exists.'))
1406 Browse and change config
1408 all_config
= get_all_config()
1409 g
['stuff'] = g
['stuff'].strip()
1412 for k
in all_config
:
1414 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1416 guide
= 'Detailed explanation can be found at ' + \
1417 color_func(c
['TWEET']['link'])(
1418 'http://rainbowstream.readthedocs.org/en/latest/#config-explanation')
1420 # Print specific config
1421 elif len(g
['stuff'].split()) == 1:
1422 if g
['stuff'] in all_config
:
1425 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1428 printNicely(red('No such config key.'))
1429 # Print specific config's default value
1430 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'default':
1431 key
= g
['stuff'].split()[0]
1433 value
= get_default_config(key
)
1434 line
= ' ' * 2 + green(key
) + ': ' + light_magenta(value
)
1438 printNicely(red('Just can not get the default.'))
1439 # Delete specific config key in config file
1440 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'drop':
1441 key
= g
['stuff'].split()[0]
1444 printNicely(green('Config key is dropped.'))
1447 printNicely(red('Just can not drop the key.'))
1448 # Set specific config
1449 elif len(g
['stuff'].split()) == 3 and g
['stuff'].split()[1] == '=':
1450 key
= g
['stuff'].split()[0]
1451 value
= g
['stuff'].split()[-1]
1452 if key
== 'THEME' and not validate_theme(value
):
1453 printNicely(red('Invalid theme\'s value.'))
1456 set_config(key
, value
)
1457 # Keys that needs to be apply immediately
1459 c
['THEME'] = reload_theme(value
, c
['THEME'])
1460 g
['decorated_name'] = lambda x
: color_func(
1461 c
['DECORATED_NAME'])('[' + x
+ ']: ')
1462 elif key
== 'PREFIX':
1463 g
['PREFIX'] = u2str(emojize(format_prefix(
1464 listname
=g
['listname'],
1465 keyword
=g
['keyword']
1468 printNicely(green('Updated successfully.'))
1471 printNicely(red('Just can not set the key.'))
1473 printNicely(light_magenta('Sorry I can\'s understand.'))
1476 def help_discover():
1481 # Discover the world
1483 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1484 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1485 'You can try ' + light_green('trend US') + ' or ' + \
1486 light_green('trend JP Tokyo') + '.\n'
1487 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1488 light_green('home 7') + ' will show 7 tweets.\n'
1490 light_green('notification') + ' will show your recent notification.\n'
1491 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1492 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1493 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1494 magenta('@mdo') + '.\n'
1495 usage
+= s
* 2 + light_green('view @mdo') + \
1496 ' will show ' + magenta('@mdo') + '\'s home.\n'
1497 usage
+= s
* 2 + light_green('s AKB48') + ' will search for "' + \
1498 light_yellow('AKB48') + '" and return 5 newest tweet. ' + \
1499 'Search can be performed with or without hashtag.\n'
1510 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1511 usage
+= s
* 2 + light_green('t oops ') + \
1512 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1514 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1515 light_yellow('[id=12]') + '.\n'
1517 light_green('quote 12 ') + ' will quote the tweet with ' + \
1518 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1519 'the quote will be canceled.\n'
1521 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1522 light_yellow('[id=12]') + '.\n'
1523 usage
+= s
* 2 + light_green('conversation 12') + ' will show the chain of ' + \
1524 'replies prior to the tweet with ' + light_yellow('[id=12]') + '.\n'
1525 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1526 light_yellow('oops') + '" to the owner of the tweet with ' + \
1527 light_yellow('[id=12]') + '.\n'
1528 usage
+= s
* 2 + light_green('repall 12 oops') + ' will reply "' + \
1529 light_yellow('oops') + '" to all people in the tweet with ' + \
1530 light_yellow('[id=12]') + '.\n'
1532 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1533 light_yellow('[id=12]') + '.\n'
1535 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1536 light_yellow('[id=12]') + '.\n'
1538 light_green('share 12 ') + ' will get the direct link of the tweet with ' + \
1539 light_yellow('[id=12]') + '.\n'
1541 light_green('del 12 ') + ' will delete tweet with ' + \
1542 light_yellow('[id=12]') + '.\n'
1543 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1544 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1545 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1546 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1550 def help_messages():
1557 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1558 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1559 light_green('inbox 7') + ' will show newest 7 messages.\n'
1560 usage
+= s
* 2 + light_green('thread 2') + ' will show full thread with ' + \
1561 light_yellow('[thread_id=2]') + '.\n'
1562 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1563 magenta('@dtvd88') + '.\n'
1564 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1565 light_yellow('[message_id=5]') + '.\n'
1569 def help_friends_and_followers():
1571 Friends and Followers
1574 # Follower and following
1576 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1578 light_green('ls fl') + \
1579 ' will list all followers (people who are following you).\n'
1581 light_green('ls fr') + \
1582 ' will list all friends (people who you are following).\n'
1583 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1584 magenta('@dtvd88') + '.\n'
1585 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1586 magenta('@dtvd88') + '.\n'
1587 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1588 magenta('@dtvd88') + '.\n'
1589 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1590 magenta('@dtvd88') + '.\n'
1591 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1592 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1593 magenta('@dtvd88') + '.\n'
1594 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1595 magenta('@dtvd88') + '.\n'
1596 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1597 magenta('@dtvd88') + ' as a spam account.\n'
1608 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1609 usage
+= s
* 2 + light_green('list') + \
1610 ' will show all lists you are belong to.\n'
1611 usage
+= s
* 2 + light_green('list home') + \
1612 ' will show timeline of list. You will be asked for list\'s name.\n'
1613 usage
+= s
* 2 + light_green('list all_mem') + \
1614 ' will show list\'s all members.\n'
1615 usage
+= s
* 2 + light_green('list all_sub') + \
1616 ' will show list\'s all subscribers.\n'
1617 usage
+= s
* 2 + light_green('list add') + \
1618 ' will add specific person to a list owned by you.' + \
1619 ' You will be asked for list\'s name and person\'s name.\n'
1620 usage
+= s
* 2 + light_green('list rm') + \
1621 ' will remove specific person from a list owned by you.' + \
1622 ' You will be asked for list\'s name and person\'s name.\n'
1623 usage
+= s
* 2 + light_green('list sub') + \
1624 ' will subscribe you to a specific list.\n'
1625 usage
+= s
* 2 + light_green('list unsub') + \
1626 ' will unsubscribe you from a specific list.\n'
1627 usage
+= s
* 2 + light_green('list own') + \
1628 ' will show all list owned by you.\n'
1629 usage
+= s
* 2 + light_green('list new') + \
1630 ' will create a new list.\n'
1631 usage
+= s
* 2 + light_green('list update') + \
1632 ' will update a list owned by you.\n'
1633 usage
+= s
* 2 + light_green('list del') + \
1634 ' will delete a list owned by you.\n'
1645 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1646 usage
+= s
* 2 + light_green('switch public #AKB') + \
1647 ' will switch to public stream and follow "' + \
1648 light_yellow('AKB') + '" keyword.\n'
1649 usage
+= s
* 2 + light_green('switch mine') + \
1650 ' will switch to your personal stream.\n'
1651 usage
+= s
* 2 + light_green('switch mine -f ') + \
1652 ' will prompt to enter the filter.\n'
1653 usage
+= s
* 3 + light_yellow('Only nicks') + \
1654 ' filter will decide nicks will be INCLUDE ONLY.\n'
1655 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1656 ' filter will decide nicks will be EXCLUDE.\n'
1657 usage
+= s
* 2 + light_green('switch list') + \
1658 ' will switch to a Twitter list\'s stream. You will be asked for list name\n'
1667 h
, w
= os
.popen('stty size', 'r').read().split()
1670 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1671 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1672 usage
+= s
+ 'You are ' + \
1673 light_yellow('already') + ' on your personal stream.\n'
1674 usage
+= s
+ 'Any update from Twitter will show up ' + \
1675 light_yellow('immediately') + '.\n'
1676 usage
+= s
+ 'In addition, following commands are available right now:\n'
1677 # Twitter help section
1679 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1680 usage
+= s
* 2 + light_green('h discover') + \
1681 ' will show help for discover commands.\n'
1682 usage
+= s
* 2 + light_green('h tweets') + \
1683 ' will show help for tweets commands.\n'
1684 usage
+= s
* 2 + light_green('h messages') + \
1685 ' will show help for messages commands.\n'
1686 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1687 ' will show help for friends and followers commands.\n'
1688 usage
+= s
* 2 + light_green('h list') + \
1689 ' will show help for list commands.\n'
1690 usage
+= s
* 2 + light_green('h stream') + \
1691 ' will show help for stream commands.\n'
1694 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1695 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1696 'will be evaluate by Python interpreter.\n'
1697 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1698 ' for current month.\n'
1701 usage
+= s
+ grey(u
'\u266A' + ' Config \n')
1702 usage
+= s
* 2 + light_green('theme') + ' will list available theme. ' + \
1703 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1704 ' theme immediately.\n'
1705 usage
+= s
* 2 + light_green('config') + ' will list all config.\n'
1707 light_green('config ASCII_ART') + ' will output current value of ' +\
1708 light_yellow('ASCII_ART') + ' config key.\n'
1710 light_green('config TREND_MAX default') + ' will output default value of ' + \
1711 light_yellow('TREND_MAX') + ' config key.\n'
1713 light_green('config CUSTOM_CONFIG drop') + ' will drop ' + \
1714 light_yellow('CUSTOM_CONFIG') + ' config key.\n'
1716 light_green('config IMAGE_ON_TERM = true') + ' will set value of ' + \
1717 light_yellow('IMAGE_ON_TERM') + ' config key to ' + \
1718 light_yellow('True') + '.\n'
1721 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1722 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1723 usage
+= s
* 2 + light_green('p') + ' will pause the stream.\n'
1724 usage
+= s
* 2 + light_green('r') + ' will unpause the stream.\n'
1725 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1726 usage
+= s
* 2 + light_green('v') + ' will show version info.\n'
1727 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1730 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1731 usage
+= s
+ 'Have fun and hang tight! \n'
1734 'discover': help_discover
,
1735 'tweets': help_tweets
,
1736 'messages': help_messages
,
1737 'friends_and_followers': help_friends_and_followers
,
1739 'stream': help_stream
,
1744 lambda: printNicely(red('No such command.'))
1752 Pause stream display
1755 printNicely(green('Stream is paused'))
1763 printNicely(green('Stream is running back now'))
1779 printNicely(green('See you next time :)'))
1787 Reset prefix of line
1790 if c
.get('USER_JSON_ERROR'):
1791 printNicely(red('Your ~/.rainbow_config.json is messed up:'))
1792 printNicely(red('>>> ' + c
['USER_JSON_ERROR']))
1794 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1797 printNicely(str(eval(g
['cmd'])))
1850 # Handle function set
1903 return dict(zip(cmdset
, funcset
)).get(cmd
, reset
)
1908 Listen to user's input
1913 ['public', 'mine', 'list'], # switch
1932 ['image'], # show image
1934 ['fl', 'fr'], # list
1936 [i
for i
in g
['message_threads']], # sent
1961 [key
for key
in dict(get_all_config())], # config
1962 g
['themes'], # theme
1967 'friends_and_followers',
1978 init_interactive_shell(d
)
1985 # Only use PREFIX as a string with raw_input
1986 line
= raw_input(g
['decorated_name'](g
['PREFIX']))
1989 # Save cmd to compare with readline buffer
1990 g
['cmd'] = line
.strip()
1991 # Get short cmd to pass to handle function
1993 cmd
= line
.split()[0]
1996 # Lock the semaphore
1998 # Save cmd to global variable and call process
1999 g
['stuff'] = ' '.join(line
.split()[1:])
2000 # Process the command
2003 if cmd
in ['switch', 't', 'rt', 'rep']:
2007 # Release the semaphore lock
2013 printNicely(red('OMG something is wrong with Twitter right now.'))
2016 def reconn_notice():
2018 Notice when Hangup or Timeout
2020 guide
= light_magenta('You can use ') + \
2021 light_green('switch') + \
2022 light_magenta(' command to return to your stream.\n')
2023 guide
+= light_magenta('Type ') + \
2024 light_green('h stream') + \
2025 light_magenta(' for more details.')
2027 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2031 def stream(domain
, args
, name
='Rainbow Stream'):
2037 c
['USER_DOMAIN']: name
,
2038 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
2039 c
['SITE_DOMAIN']: name
,
2042 ascii_art(art_dict
[domain
])
2043 # These arguments are optional:
2045 timeout
=0.5, # To check g['stream_stop'] after each 0.5 s
2047 heartbeat_timeout
=c
['HEARTBEAT_TIMEOUT'] * 60)
2050 if args
.track_keywords
:
2051 query_args
['track'] = args
.track_keywords
2053 stream
= TwitterStream(
2058 if domain
== c
['USER_DOMAIN']:
2059 tweet_iter
= stream
.user(**query_args
)
2060 elif domain
== c
['SITE_DOMAIN']:
2061 tweet_iter
= stream
.site(**query_args
)
2063 if args
.track_keywords
:
2064 tweet_iter
= stream
.statuses
.filter(**query_args
)
2066 tweet_iter
= stream
.statuses
.sample()
2067 # Block new stream until other one exits
2068 StreamLock
.acquire()
2069 g
['stream_stop'] = False
2070 last_tweet_time
= time
.time()
2071 for tweet
in tweet_iter
:
2073 printNicely('-- None --')
2074 elif tweet
is Timeout
:
2075 # Because the stream check for each 0.3s
2076 # so we shouldn't output anything here
2077 if(g
['stream_stop']):
2078 StreamLock
.release()
2080 elif tweet
is HeartbeatTimeout
:
2081 printNicely('-- Heartbeat Timeout --')
2083 StreamLock
.release()
2085 elif tweet
is Hangup
:
2086 printNicely('-- Hangup --')
2088 StreamLock
.release()
2090 elif tweet
.get('text'):
2091 # Slow down the stream by STREAM_DELAY config key
2092 if time
.time() - last_tweet_time
< c
['STREAM_DELAY']:
2094 last_tweet_time
= time
.time()
2095 # Check the semaphore pause and lock (stream process only)
2103 keyword
=args
.track_keywords
,
2108 # Current readline buffer
2109 current_buffer
= readline
.get_line_buffer().strip()
2110 # There is an unexpected behaviour in MacOSX readline + Python 2:
2111 # after completely delete a word after typing it,
2112 # somehow readline buffer still contains
2113 # the 1st character of that word
2114 if current_buffer
and g
['cmd'] != current_buffer
:
2116 g
['decorated_name'](g
['PREFIX']) + current_buffer
)
2118 elif not c
['HIDE_PROMPT']:
2119 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2121 elif tweet
.get('direct_message'):
2122 # Check the semaphore pause and lock (stream process only)
2127 print_message(tweet
['direct_message'])
2128 elif tweet
.get('event'):
2129 c
['events'].append(tweet
)
2131 except TwitterHTTPError
as e
:
2134 magenta('We have connection problem with twitter stream API right now :('))
2135 detail_twitter_error(e
)
2136 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2138 except (URLError
, ConnectionResetError
):
2140 magenta('There seems to be a connection problem.'))
2150 args
= parse_arguments()
2154 # Twitter API connection problem
2155 except TwitterHTTPError
as e
:
2158 magenta('We have connection problem with twitter REST API right now :('))
2159 detail_twitter_error(e
)
2162 # Proxy connection problem
2163 except (socks
.ProxyConnectionError
, URLError
):
2165 magenta('There seems to be a connection problem.'))
2167 magenta('You might want to check your proxy settings (host, port and type)!'))
2171 # Spawn stream thread
2172 target
= args
.stream
.split()[0]
2173 if target
== 'public':
2175 keyword
= args
.stream
.split()[1]
2176 if keyword
[0] == '#':
2177 keyword
= keyword
[1:]
2178 args
.track_keywords
= keyword
2179 # Set the variable to tracked keyword
2180 g
['keyword'] = keyword
2182 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
2184 th
= threading
.Thread(
2192 printNicely(red('Public requires a keyword! Loading your personal stream.'))
2194 th
= threading
.Thread(
2199 g
['original_name']))
2202 elif target
== "list":
2204 owner
, slug
= check_slug(args
.stream
.split()[1])
2205 # Force python 2 not redraw readline buffer
2206 listname
= '/'.join([owner
, slug
])
2207 # Set the listname variable
2208 # and reset tracked keyword
2209 g
['listname'] = listname
2211 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
2212 listname
=g
['listname']
2214 printNicely(light_yellow('getting list members ...'))
2216 t
= Twitter(auth
=authen())
2219 while next_cursor
!= 0:
2220 m
= t
.lists
.members(
2222 owner_screen_name
=owner
,
2224 include_entities
=False)
2225 for u
in m
['users']:
2226 members
.append('@' + u
['screen_name'])
2227 next_cursor
= m
['next_cursor']
2228 printNicely(light_yellow('... done.'))
2229 # Build thread filter array
2230 args
.filter = members
2232 g
['stream_stop'] = True
2234 th
= threading
.Thread(
2244 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
2246 printNicely(red('List requieres a correct name of a list! Loading your personal stream.'))
2248 th
= threading
.Thread(
2253 g
['original_name']))
2256 elif target
== "mine":
2258 th
= threading
.Thread(
2263 g
['original_name']))
2267 printNicely(red('Wrong -s/--stream argument given. Loading your personal stream.'))
2269 th
= threading
.Thread(
2274 g
['original_name']))
2278 # Start listen process