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.')
74 help='Display images using 24bit color codes.')
78 help='Use HTTP/SOCKS proxy for network connections.')
83 help='HTTP/SOCKS proxy port (Default: 8080).')
88 help='Proxy type (HTTP, SOCKS4, SOCKS5; Default: SOCKS5).')
89 return parser
.parse_args()
92 def proxy_connect(args
):
94 Connect to specified proxy
97 # Setup proxy by monkeypatching the standard lib
98 if args
.proxy_type
.lower() == "socks5" or not args
.proxy_type
:
99 socks
.set_default_proxy(
100 socks
.SOCKS5
, args
.proxy_host
,
101 int(args
.proxy_port
))
102 elif args
.proxy_type
.lower() == "http":
103 socks
.set_default_proxy(
104 socks
.HTTP
, args
.proxy_host
,
105 int(args
.proxy_port
))
106 elif args
.proxy_type
.lower() == "socks4":
107 socks
.set_default_proxy(
108 socks
.SOCKS4
, args
.proxy_host
,
109 int(args
.proxy_port
))
112 magenta('Sorry, wrong proxy type specified! Aborting...'))
114 socket
.socket
= socks
.socksocket
119 Authenticate with Twitter OAuth
121 # When using rainbow stream you must authorize.
122 twitter_credential
= os
.environ
.get(
126 '')) + os
.sep
+ '.rainbow_oauth'
127 if not os
.path
.exists(twitter_credential
):
128 oauth_dance('Rainbow Stream',
132 oauth_token
, oauth_token_secret
= read_token_file(twitter_credential
)
140 def build_mute_dict(dict_data
=False):
144 t
= Twitter(auth
=authen())
147 screen_name_list
= []
150 while next_cursor
!= 0:
151 list = t
.mutes
.users
.list(
152 screen_name
=g
['original_name'],
155 include_entities
=False,
157 screen_name_list
+= ['@' + u
['screen_name'] for u
in list['users']]
158 name_list
+= [u
['name'] for u
in list['users']]
159 next_cursor
= list['next_cursor']
160 # Return dict or list
162 return dict(zip(screen_name_list
, name_list
))
164 return screen_name_list
169 Save traceback when run in debug mode
172 g
['traceback'].append(traceback
.format_exc())
175 def upgrade_center():
177 Check latest and notify to upgrade
180 current
= pkg_resources
.get_distribution('rainbowstream').version
181 url
= 'https://raw.githubusercontent.com/DTVD/rainbowstream/master/setup.py'
182 readme
= requests
.get(url
).text
183 latest
= readme
.split('version = \'')[1].split('\'')[0]
184 g
['using_latest'] = current
== latest
185 if not g
['using_latest']:
186 notice
= light_magenta('RainbowStream latest version is ')
187 notice
+= light_green(latest
)
188 notice
+= light_magenta(' while your current version is ')
189 notice
+= light_yellow(current
) + '\n'
190 notice
+= light_magenta('You should upgrade with ')
191 notice
+= light_green('pip install -U rainbowstream')
194 notice
= light_yellow('You are running latest version (')
195 notice
+= light_green(current
)
196 notice
+= light_yellow(')')
207 ctrl_c_handler
= lambda signum
, frame
: quit()
208 signal
.signal(signal
.SIGINT
, ctrl_c_handler
)
212 t
= Twitter(auth
=authen())
213 credential
= t
.account
.verify_credentials()
214 screen_name
= '@' + credential
['screen_name']
215 name
= credential
['name']
216 c
['original_name'] = g
['original_name'] = screen_name
[1:]
217 g
['listname'] = g
['keyword'] = ''
218 g
['PREFIX'] = u2str(emojize(format_prefix()))
219 g
['full_name'] = name
220 g
['decorated_name'] = lambda x
: color_func(
221 c
['DECORATED_NAME'])('[' + x
+ ']: ', rl
=True)
223 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
224 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
227 g
['message_threads'] = {}
230 # Debug option default = True
237 # Init tweet dict and message dict
239 c
['message_dict'] = []
241 c
['IMAGE_ON_TERM'] = args
.image_on_term
242 set_config('IMAGE_ON_TERM', str(c
['IMAGE_ON_TERM']))
244 c
['24BIT'] = args
.color_24bit
245 # Resize images based on the current terminal size
246 set_config('IMAGE_RESIZE_TO_FIT', str(c
.get('IMAGE_RESIZE_TO_FIT', False)))
247 # Check type of ONLY_LIST and IGNORE_LIST
248 if not isinstance(c
['ONLY_LIST'], list):
249 printNicely(red('ONLY_LIST is not a valid list value.'))
251 if not isinstance(c
['IGNORE_LIST'], list):
252 printNicely(red('IGNORE_LIST is not a valid list value.'))
253 c
['IGNORE_LIST'] = []
255 c
['IGNORE_LIST'] += build_mute_dict()
262 t
= Twitter(auth
=authen())
263 # Get country and town
265 country
= g
['stuff'].split()[0]
269 town
= g
['stuff'].split()[1]
272 avail
= t
.trends
.available()
275 trends
= t
.trends
.place(_id
=1)[0]['trends']
278 for location
in avail
:
279 # Search for country and Town
281 if location
['countryCode'] == country \
282 and location
['placeType']['name'] == 'Town' \
283 and location
['name'] == town
:
284 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
286 # Search for country only
288 if location
['countryCode'] == country \
289 and location
['placeType']['name'] == 'Country':
290 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
298 t
= Twitter(auth
=authen())
299 num
= c
['HOME_TWEET_NUM']
300 if g
['stuff'].isdigit():
301 num
= int(g
['stuff'])
302 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
312 for e
in c
['events']:
316 printNicely(magenta('Nothing at this time.'))
323 t
= Twitter(auth
=authen())
324 num
= c
['HOME_TWEET_NUM']
325 if g
['stuff'].isdigit():
326 num
= int(g
['stuff'])
327 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
334 Show profile of a specific user
336 t
= Twitter(auth
=authen())
338 screen_name
= g
['stuff'].split()[0]
340 printNicely(red('Sorry I can\'t understand.'))
342 if screen_name
.startswith('@'):
345 screen_name
=screen_name
[1:],
346 include_entities
=False)
350 printNicely(red('No user.'))
352 printNicely(red('A name should begin with a \'@\''))
359 t
= Twitter(auth
=authen())
361 user
= g
['stuff'].split()[0]
363 printNicely(red('Sorry I can\'t understand.'))
367 num
= int(g
['stuff'].split()[1])
369 num
= c
['HOME_TWEET_NUM']
370 for tweet
in reversed(
371 t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
375 printNicely(red('A name should begin with a \'@\''))
378 def view_my_tweets():
380 Display user's recent tweets.
382 t
= Twitter(auth
=authen())
384 num
= int(g
['stuff'])
386 num
= c
['HOME_TWEET_NUM']
387 for tweet
in reversed(
388 t
.statuses
.user_timeline(count
=num
, screen_name
=g
['original_name'])):
397 t
= Twitter(auth
=authen())
399 query
= g
['stuff'].strip()
401 printNicely(red('Sorry I can\'t understand.'))
403 type = c
['SEARCH_TYPE']
404 if type not in ['mixed', 'recent', 'popular']:
406 max_record
= c
['SEARCH_MAX_RECORD']
407 count
= min(max_record
, 100)
409 rel
= t
.search
.tweets(
416 printNicely('Newest tweets:')
417 for i
in reversed(xrange(count
)):
418 draw(t
=rel
[i
], keyword
=query
)
421 printNicely(magenta('I\'m afraid there is no result'))
428 t
= Twitter(auth
=authen())
429 t
.statuses
.update(status
=g
['stuff'])
436 t
= Twitter(auth
=authen())
438 id = int(g
['stuff'].split()[0])
440 printNicely(red('Sorry I can\'t understand.'))
442 tid
= c
['tweet_dict'][id]
443 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
451 t
= Twitter(auth
=authen())
453 id = int(g
['stuff'].split()[0])
455 printNicely(red('Sorry I can\'t understand.'))
457 tid
= c
['tweet_dict'][id]
458 tweet
= t
.statuses
.show(id=tid
)
460 formater
= format_quote(tweet
)
464 prefix
= light_magenta('Compose your ', rl
=True) + \
465 light_green('#comment: ', rl
=True)
466 comment
= raw_input(prefix
)
468 quote
= comment
.join(formater
.split('#comment'))
469 t
.statuses
.update(status
=quote
)
471 printNicely(light_magenta('No text added.'))
478 t
= Twitter(auth
=authen())
481 id = int(g
['stuff'].split()[0])
483 printNicely(red('Sorry I can\'t understand.'))
485 tid
= c
['tweet_dict'][id]
486 # Get display num if exist
488 num
= int(g
['stuff'].split()[1])
490 num
= c
['RETWEETS_SHOW_NUM']
491 # Get result and display
492 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
494 printNicely(magenta('This tweet has no retweet.'))
496 for tweet
in reversed(rt_ary
):
505 t
= Twitter(auth
=authen())
507 id = int(g
['stuff'].split()[0])
509 printNicely(red('Sorry I can\'t understand.'))
511 tid
= c
['tweet_dict'][id]
512 tweet
= t
.statuses
.show(id=tid
)
513 limit
= c
['CONVERSATION_MAX']
515 thread_ref
.append(tweet
)
516 prev_tid
= tweet
['in_reply_to_status_id']
517 while prev_tid
and limit
:
519 tweet
= t
.statuses
.show(id=prev_tid
)
520 prev_tid
= tweet
['in_reply_to_status_id']
521 thread_ref
.append(tweet
)
523 for tweet
in reversed(thread_ref
):
532 t
= Twitter(auth
=authen())
534 id = int(g
['stuff'].split()[0])
536 printNicely(red('Sorry I can\'t understand.'))
538 tid
= c
['tweet_dict'][id]
539 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
540 status
= ' '.join(g
['stuff'].split()[1:])
541 status
= '@' + user
+ ' ' + str2u(status
)
542 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
549 t
= Twitter(auth
=authen())
551 id = int(g
['stuff'].split()[0])
553 printNicely(red('Sorry I can\'t understand.'))
555 tid
= c
['tweet_dict'][id]
556 original_tweet
= t
.statuses
.show(id=tid
)
557 text
= original_tweet
['text']
558 nick_ary
= [original_tweet
['user']['screen_name']]
559 for user
in list(original_tweet
['entities']['user_mentions']):
560 if user
['screen_name'] not in nick_ary \
561 and user
['screen_name'] != g
['original_name']:
562 nick_ary
.append(user
['screen_name'])
563 status
= ' '.join(g
['stuff'].split()[1:])
564 status
= ' '.join(['@' + nick
for nick
in nick_ary
]) + ' ' + str2u(status
)
565 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
572 t
= Twitter(auth
=authen())
574 id = int(g
['stuff'].split()[0])
576 printNicely(red('Sorry I can\'t understand.'))
578 tid
= c
['tweet_dict'][id]
579 t
.favorites
.create(_id
=tid
, include_entities
=False)
580 printNicely(green('Favorited.'))
581 draw(t
.statuses
.show(id=tid
))
589 t
= Twitter(auth
=authen())
591 id = int(g
['stuff'].split()[0])
593 printNicely(red('Sorry I can\'t understand.'))
595 tid
= c
['tweet_dict'][id]
596 t
.favorites
.destroy(_id
=tid
)
597 printNicely(green('Okay it\'s unfavorited.'))
598 draw(t
.statuses
.show(id=tid
))
604 Copy url of a tweet to clipboard
606 t
= Twitter(auth
=authen())
608 id = int(g
['stuff'].split()[0])
609 tid
= c
['tweet_dict'][id]
611 printNicely(red('Tweet id is not valid.'))
613 tweet
= t
.statuses
.show(id=tid
)
614 url
= 'https://twitter.com/' + \
615 tweet
['user']['screen_name'] + '/status/' + str(tid
)
617 if platform
.system().lower() == 'darwin':
618 os
.system("echo '%s' | pbcopy" % url
)
619 printNicely(green('Copied tweet\'s url to clipboard.'))
621 printNicely('Direct link: ' + yellow(url
))
628 t
= Twitter(auth
=authen())
630 id = int(g
['stuff'].split()[0])
632 printNicely(red('Sorry I can\'t understand.'))
634 tid
= c
['tweet_dict'][id]
635 t
.statuses
.destroy(id=tid
)
636 printNicely(green('Okay it\'s gone.'))
643 t
= Twitter(auth
=authen())
645 target
= g
['stuff'].split()[0]
646 if target
!= 'image':
648 id = int(g
['stuff'].split()[1])
649 tid
= c
['tweet_dict'][id]
650 tweet
= t
.statuses
.show(id=tid
)
651 media
= tweet
['entities']['media']
653 res
= requests
.get(m
['media_url'])
654 img
= Image
.open(BytesIO(res
.content
))
658 printNicely(red('Sorry I can\'t show this image.'))
665 t
= Twitter(auth
=authen())
667 if not g
['stuff'].isdigit():
669 tid
= c
['tweet_dict'][int(g
['stuff'])]
670 tweet
= t
.statuses
.show(id=tid
)
671 urls
= tweet
['entities']['urls']
673 printNicely(light_magenta('No url here @.@!'))
677 expanded_url
= url
['expanded_url']
678 webbrowser
.open(expanded_url
)
681 printNicely(red('Sorry I can\'t open url in this tweet.'))
688 t
= Twitter(auth
=authen())
689 num
= c
['MESSAGES_DISPLAY']
690 if g
['stuff'].isdigit():
696 inbox
= inbox
+ t
.direct_messages(
699 include_entities
=False,
704 inbox
= inbox
+ t
.direct_messages(
707 include_entities
=False,
711 num
= c
['MESSAGES_DISPLAY']
712 if g
['stuff'].isdigit():
717 sent
= sent
+ t
.direct_messages
.sent(
720 include_entities
=False,
725 sent
= sent
+ t
.direct_messages
.sent(
728 include_entities
=False,
733 uniq_inbox
= list(set(
734 [(m
['sender_screen_name'], m
['sender']['name']) for m
in inbox
]
736 uniq_sent
= list(set(
737 [(m
['recipient_screen_name'], m
['recipient']['name']) for m
in sent
]
739 for partner
in uniq_inbox
:
740 inbox_ary
= [m
for m
in inbox
if m
['sender_screen_name'] == partner
[0]]
742 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
743 d
[partner
] = inbox_ary
+ sent_ary
744 for partner
in uniq_sent
:
747 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
748 g
['message_threads'] = print_threads(d
)
753 View a thread of message
756 thread_id
= int(g
['stuff'])
758 g
['message_threads'][thread_id
],
763 printNicely(red('No such thread.'))
768 Send a direct message
770 t
= Twitter(auth
=authen())
772 user
= g
['stuff'].split()[0]
773 if user
[0].startswith('@'):
774 content
= ' '.join(g
['stuff'].split()[1:])
775 t
.direct_messages
.new(
776 screen_name
=user
[1:],
779 printNicely(green('Message sent.'))
781 printNicely(red('A name should begin with a \'@\''))
784 printNicely(red('Sorry I can\'t understand.'))
791 t
= Twitter(auth
=authen())
793 id = int(g
['stuff'].split()[0])
795 printNicely(red('Sorry I can\'t understand.'))
796 mid
= c
['message_dict'][id]
797 t
.direct_messages
.destroy(id=mid
)
798 printNicely(green('Message deleted.'))
803 List friends for followers
805 t
= Twitter(auth
=authen())
808 name
= g
['stuff'].split()[1]
809 if name
.startswith('@'):
812 printNicely(red('A name should begin with a \'@\''))
813 raise Exception('Invalid name')
815 name
= g
['original_name']
816 # Get list followers or friends
818 target
= g
['stuff'].split()[0]
820 printNicely(red('Omg some syntax is wrong.'))
823 d
= {'fl': 'followers', 'fr': 'friends'}
827 while next_cursor
!= 0:
828 list = getattr(t
, d
[target
]).list(
832 include_entities
=False,
834 for u
in list['users']:
835 rel
[u
['name']] = '@' + u
['screen_name']
836 next_cursor
= list['next_cursor']
838 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
840 user
= ' ' + cycle_color(name
)
841 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
849 t
= Twitter(auth
=authen())
850 screen_name
= g
['stuff'].split()[0]
851 if screen_name
.startswith('@'):
852 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
853 printNicely(green('You are following ' + screen_name
+ ' now!'))
855 printNicely(red('A name should begin with a \'@\''))
862 t
= Twitter(auth
=authen())
863 screen_name
= g
['stuff'].split()[0]
864 if screen_name
.startswith('@'):
865 t
.friendships
.destroy(
866 screen_name
=screen_name
[1:],
867 include_entities
=False)
868 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
870 printNicely(red('A name should begin with a \'@\''))
877 t
= Twitter(auth
=authen())
879 screen_name
= g
['stuff'].split()[0]
881 printNicely(red('A name should be specified. '))
883 if screen_name
.startswith('@'):
885 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
886 if isinstance(rel
, dict):
887 printNicely(green(screen_name
+ ' is muted.'))
888 c
['IGNORE_LIST'] += [unc(screen_name
)]
889 c
['IGNORE_LIST'] = list(set(c
['IGNORE_LIST']))
891 printNicely(red(rel
))
894 printNicely(red('Something is wrong, can not mute now :('))
896 printNicely(red('A name should begin with a \'@\''))
903 t
= Twitter(auth
=authen())
905 screen_name
= g
['stuff'].split()[0]
907 printNicely(red('A name should be specified. '))
909 if screen_name
.startswith('@'):
911 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
912 if isinstance(rel
, dict):
913 printNicely(green(screen_name
+ ' is unmuted.'))
914 c
['IGNORE_LIST'].remove(screen_name
)
916 printNicely(red(rel
))
918 printNicely(red('Maybe you are not muting this person ?'))
920 printNicely(red('A name should begin with a \'@\''))
927 # Get dict of muting users
928 md
= build_mute_dict(dict_data
=True)
929 printNicely('All: ' + str(len(md
)) + ' people.')
931 user
= ' ' + cycle_color(md
[name
])
932 user
+= color_func(c
['TWEET']['nick'])(' ' + name
+ ' ')
934 # Update from Twitter
935 c
['IGNORE_LIST'] = [n
for n
in md
]
942 t
= Twitter(auth
=authen())
943 screen_name
= g
['stuff'].split()[0]
944 if screen_name
.startswith('@'):
946 screen_name
=screen_name
[1:],
947 include_entities
=False,
949 printNicely(green('You blocked ' + screen_name
+ '.'))
951 printNicely(red('A name should begin with a \'@\''))
958 t
= Twitter(auth
=authen())
959 screen_name
= g
['stuff'].split()[0]
960 if screen_name
.startswith('@'):
962 screen_name
=screen_name
[1:],
963 include_entities
=False,
965 printNicely(green('Unblock ' + screen_name
+ ' success!'))
967 printNicely(red('A name should begin with a \'@\''))
972 Report a user as a spam account
974 t
= Twitter(auth
=authen())
975 screen_name
= g
['stuff'].split()[0]
976 if screen_name
.startswith('@'):
978 screen_name
=screen_name
[1:])
979 printNicely(green('You reported ' + screen_name
+ '.'))
981 printNicely(red('Sorry I can\'t understand.'))
989 list_name
= raw_input(
990 light_magenta('Give me the list\'s name ("@owner/list_name"): ', rl
=True))
991 # Get list name and owner
993 owner
, slug
= list_name
.split('/')
994 if slug
.startswith('@'):
999 light_magenta('List name should follow "@owner/list_name" format.'))
1000 raise Exception('Wrong list name')
1003 def check_slug(list_name
):
1007 # Get list name and owner
1009 owner
, slug
= list_name
.split('/')
1010 if slug
.startswith('@'):
1015 light_magenta('List name should follow "@owner/list_name" format.'))
1016 raise Exception('Wrong list name')
1023 rel
= t
.lists
.list(screen_name
=g
['original_name'])
1027 printNicely(light_magenta('You belong to no lists :)'))
1034 owner
, slug
= get_slug()
1035 res
= t
.lists
.statuses(
1037 owner_screen_name
=owner
,
1038 count
=c
['LIST_MAX'],
1039 include_entities
=False)
1040 for tweet
in reversed(res
):
1045 def list_members(t
):
1049 owner
, slug
= get_slug()
1053 while next_cursor
!= 0:
1054 m
= t
.lists
.members(
1056 owner_screen_name
=owner
,
1058 include_entities
=False)
1059 for u
in m
['users']:
1060 rel
[u
['name']] = '@' + u
['screen_name']
1061 next_cursor
= m
['next_cursor']
1062 printNicely('All: ' + str(len(rel
)) + ' members.')
1064 user
= ' ' + cycle_color(name
)
1065 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1069 def list_subscribers(t
):
1073 owner
, slug
= get_slug()
1077 while next_cursor
!= 0:
1078 m
= t
.lists
.subscribers(
1080 owner_screen_name
=owner
,
1082 include_entities
=False)
1083 for u
in m
['users']:
1084 rel
[u
['name']] = '@' + u
['screen_name']
1085 next_cursor
= m
['next_cursor']
1086 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
1088 user
= ' ' + cycle_color(name
)
1089 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1095 Add specific user to a list
1097 owner
, slug
= get_slug()
1099 user_name
= raw_input(
1101 'Give me name of the newbie: ',
1103 if user_name
.startswith('@'):
1104 user_name
= user_name
[1:]
1106 t
.lists
.members
.create(
1108 owner_screen_name
=owner
,
1109 screen_name
=user_name
)
1110 printNicely(green('Added.'))
1113 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
1118 Remove specific user from a list
1120 owner
, slug
= get_slug()
1122 user_name
= raw_input(
1124 'Give me name of the unlucky one: ',
1126 if user_name
.startswith('@'):
1127 user_name
= user_name
[1:]
1129 t
.lists
.members
.destroy(
1131 owner_screen_name
=owner
,
1132 screen_name
=user_name
)
1133 printNicely(green('Gone.'))
1136 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
1139 def list_subscribe(t
):
1143 owner
, slug
= get_slug()
1146 t
.lists
.subscribers
.create(
1148 owner_screen_name
=owner
)
1149 printNicely(green('Done.'))
1153 light_magenta('I\'m sorry you can not subscribe to this list.'))
1156 def list_unsubscribe(t
):
1160 owner
, slug
= get_slug()
1163 t
.lists
.subscribers
.destroy(
1165 owner_screen_name
=owner
)
1166 printNicely(green('Done.'))
1170 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
1179 while next_cursor
!= 0:
1180 res
= t
.lists
.ownerships(
1181 screen_name
=g
['original_name'],
1184 next_cursor
= res
['next_cursor']
1188 printNicely(light_magenta('You own no lists :)'))
1195 name
= raw_input(light_magenta('New list\'s name: ', rl
=True))
1198 'New list\'s mode (public/private): ',
1200 description
= raw_input(
1202 'New list\'s description: ',
1208 description
=description
)
1209 printNicely(green(name
+ ' list is created.'))
1212 printNicely(red('Oops something is wrong with Twitter :('))
1221 'Your list that you want to update: ',
1225 'Update name (leave blank to unchange): ',
1227 mode
= raw_input(light_magenta('Update mode (public/private): ', rl
=True))
1228 description
= raw_input(light_magenta('Update description: ', rl
=True))
1232 slug
='-'.join(slug
.split()),
1233 owner_screen_name
=g
['original_name'],
1236 description
=description
)
1240 owner_screen_name
=g
['original_name'],
1242 description
=description
)
1243 printNicely(green(slug
+ ' list is updated.'))
1246 printNicely(red('Oops something is wrong with Twitter :('))
1255 'Your list that you want to delete: ',
1259 slug
='-'.join(slug
.split()),
1260 owner_screen_name
=g
['original_name'])
1261 printNicely(green(slug
+ ' list is deleted.'))
1264 printNicely(red('Oops something is wrong with Twitter :('))
1271 t
= Twitter(auth
=authen())
1272 # List all lists or base on action
1274 g
['list_action'] = g
['stuff'].split()[0]
1281 'all_mem': list_members
,
1282 'all_sub': list_subscribers
,
1285 'sub': list_subscribe
,
1286 'unsub': list_unsubscribe
,
1289 'update': list_update
,
1293 return action_ary
[g
['list_action']](t
)
1295 printNicely(red('Please try again.'))
1303 target
= g
['stuff'].split()[0]
1305 args
= parse_arguments()
1307 if g
['stuff'].split()[-1] == '-f':
1308 guide
= 'To ignore an option, just hit Enter key.'
1309 printNicely(light_magenta(guide
))
1310 only
= raw_input('Only nicks [Ex: @xxx,@yy]: ')
1311 ignore
= raw_input('Ignore nicks [Ex: @xxx,@yy]: ')
1312 args
.filter = filter(None, only
.split(','))
1313 args
.ignore
= filter(None, ignore
.split(','))
1315 printNicely(red('Sorry, wrong format.'))
1318 g
['stream_stop'] = True
1320 stuff
= g
['stuff'].split()[1]
1325 'public': spawn_public_stream
,
1326 'list': spawn_list_stream
,
1327 'mine': spawn_personal_stream
,
1329 spawn_dict
.get(target
)(args
, stuff
)
1332 printNicely(red('Sorry I can\'t understand.'))
1337 Unix's command `cal`
1340 rel
= os
.popen('cal').read().split('\n')
1343 show_calendar(month
, date
, rel
)
1348 List and change theme
1352 for theme
in g
['themes']:
1353 line
= light_magenta(theme
)
1354 if c
['THEME'] == theme
:
1355 line
= ' ' * 2 + light_yellow('* ') + line
1357 line
= ' ' * 4 + line
1363 c
['THEME'] = reload_theme(g
['stuff'], c
['THEME'])
1364 # Redefine decorated_name
1365 g
['decorated_name'] = lambda x
: color_func(
1366 c
['DECORATED_NAME'])(
1368 printNicely(green('Theme changed.'))
1370 printNicely(red('No such theme exists.'))
1375 Browse and change config
1377 all_config
= get_all_config()
1378 g
['stuff'] = g
['stuff'].strip()
1381 for k
in all_config
:
1383 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1385 guide
= 'Detailed explanation can be found at ' + \
1386 color_func(c
['TWEET']['link'])(
1387 'http://rainbowstream.readthedocs.org/en/latest/#config-explanation')
1389 # Print specific config
1390 elif len(g
['stuff'].split()) == 1:
1391 if g
['stuff'] in all_config
:
1394 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1397 printNicely(red('No such config key.'))
1398 # Print specific config's default value
1399 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'default':
1400 key
= g
['stuff'].split()[0]
1402 value
= get_default_config(key
)
1403 line
= ' ' * 2 + green(key
) + ': ' + light_magenta(value
)
1407 printNicely(red('Just can not get the default.'))
1408 # Delete specific config key in config file
1409 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'drop':
1410 key
= g
['stuff'].split()[0]
1413 printNicely(green('Config key is dropped.'))
1416 printNicely(red('Just can not drop the key.'))
1417 # Set specific config
1418 elif len(g
['stuff'].split()) == 3 and g
['stuff'].split()[1] == '=':
1419 key
= g
['stuff'].split()[0]
1420 value
= g
['stuff'].split()[-1]
1421 if key
== 'THEME' and not validate_theme(value
):
1422 printNicely(red('Invalid theme\'s value.'))
1425 set_config(key
, value
)
1426 # Keys that needs to be apply immediately
1428 c
['THEME'] = reload_theme(value
, c
['THEME'])
1429 g
['decorated_name'] = lambda x
: color_func(
1430 c
['DECORATED_NAME'])('[' + x
+ ']: ')
1431 elif key
== 'PREFIX':
1432 g
['PREFIX'] = u2str(emojize(format_prefix(
1433 listname
=g
['listname'],
1434 keyword
=g
['keyword']
1437 printNicely(green('Updated successfully.'))
1440 printNicely(red('Just can not set the key.'))
1442 printNicely(light_magenta('Sorry I can\'s understand.'))
1445 def help_discover():
1450 # Discover the world
1452 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1453 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1454 'You can try ' + light_green('trend US') + ' or ' + \
1455 light_green('trend JP Tokyo') + '.\n'
1456 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1457 light_green('home 7') + ' will show 7 tweets.\n'
1459 light_green('notification') + ' will show your recent notification.\n'
1460 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1461 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1462 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1463 magenta('@mdo') + '.\n'
1464 usage
+= s
* 2 + light_green('view @mdo') + \
1465 ' will show ' + magenta('@mdo') + '\'s home.\n'
1466 usage
+= s
* 2 + light_green('s AKB48') + ' will search for "' + \
1467 light_yellow('AKB48') + '" and return 5 newest tweet. ' + \
1468 'Search can be performed with or without hashtag.\n'
1479 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1480 usage
+= s
* 2 + light_green('t oops ') + \
1481 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1483 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1484 light_yellow('[id=12]') + '.\n'
1486 light_green('quote 12 ') + ' will quote the tweet with ' + \
1487 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1488 'the quote will be canceled.\n'
1490 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1491 light_yellow('[id=12]') + '.\n'
1492 usage
+= s
* 2 + light_green('conversation 12') + ' will show the chain of ' + \
1493 'replies prior to the tweet with ' + light_yellow('[id=12]') + '.\n'
1494 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1495 light_yellow('oops') + '" to the owner of the tweet with ' + \
1496 light_yellow('[id=12]') + '.\n'
1497 usage
+= s
* 2 + light_green('repall 12 oops') + ' will reply "' + \
1498 light_yellow('oops') + '" to all people in the tweet with ' + \
1499 light_yellow('[id=12]') + '.\n'
1501 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1502 light_yellow('[id=12]') + '.\n'
1504 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1505 light_yellow('[id=12]') + '.\n'
1507 light_green('share 12 ') + ' will get the direct link of the tweet with ' + \
1508 light_yellow('[id=12]') + '.\n'
1510 light_green('mytw 2 ') + ' will show your last two tweets.\n'
1512 light_green('del 12 ') + ' will delete tweet with ' + \
1513 light_yellow('[id=12]') + '.\n'
1514 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1515 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1516 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1517 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1521 def help_messages():
1528 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1529 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1530 light_green('inbox 7') + ' will show newest 7 messages.\n'
1531 usage
+= s
* 2 + light_green('thread 2') + ' will show full thread with ' + \
1532 light_yellow('[thread_id=2]') + '.\n'
1533 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1534 magenta('@dtvd88') + '.\n'
1535 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1536 light_yellow('[message_id=5]') + '.\n'
1540 def help_friends_and_followers():
1542 Friends and Followers
1545 # Follower and following
1547 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1549 light_green('ls fl') + \
1550 ' will list all followers (people who are following you).\n'
1552 light_green('ls fr') + \
1553 ' will list all friends (people who you are following).\n'
1554 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1555 magenta('@dtvd88') + '.\n'
1556 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1557 magenta('@dtvd88') + '.\n'
1558 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1559 magenta('@dtvd88') + '.\n'
1560 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1561 magenta('@dtvd88') + '.\n'
1562 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1563 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1564 magenta('@dtvd88') + '.\n'
1565 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1566 magenta('@dtvd88') + '.\n'
1567 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1568 magenta('@dtvd88') + ' as a spam account.\n'
1579 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1580 usage
+= s
* 2 + light_green('list') + \
1581 ' will show all lists you are belong to.\n'
1582 usage
+= s
* 2 + light_green('list home') + \
1583 ' will show timeline of list. You will be asked for list\'s name.\n'
1584 usage
+= s
* 2 + light_green('list all_mem') + \
1585 ' will show list\'s all members.\n'
1586 usage
+= s
* 2 + light_green('list all_sub') + \
1587 ' will show list\'s all subscribers.\n'
1588 usage
+= s
* 2 + light_green('list add') + \
1589 ' will add specific person to a list owned by you.' + \
1590 ' You will be asked for list\'s name and person\'s name.\n'
1591 usage
+= s
* 2 + light_green('list rm') + \
1592 ' will remove specific person from a list owned by you.' + \
1593 ' You will be asked for list\'s name and person\'s name.\n'
1594 usage
+= s
* 2 + light_green('list sub') + \
1595 ' will subscribe you to a specific list.\n'
1596 usage
+= s
* 2 + light_green('list unsub') + \
1597 ' will unsubscribe you from a specific list.\n'
1598 usage
+= s
* 2 + light_green('list own') + \
1599 ' will show all list owned by you.\n'
1600 usage
+= s
* 2 + light_green('list new') + \
1601 ' will create a new list.\n'
1602 usage
+= s
* 2 + light_green('list update') + \
1603 ' will update a list owned by you.\n'
1604 usage
+= s
* 2 + light_green('list del') + \
1605 ' will delete a list owned by you.\n'
1616 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1617 usage
+= s
* 2 + light_green('switch public #AKB') + \
1618 ' will switch to public stream and follow "' + \
1619 light_yellow('AKB') + '" keyword.\n'
1620 usage
+= s
* 2 + light_green('switch mine') + \
1621 ' will switch to your personal stream.\n'
1622 usage
+= s
* 2 + light_green('switch mine -f ') + \
1623 ' will prompt to enter the filter.\n'
1624 usage
+= s
* 3 + light_yellow('Only nicks') + \
1625 ' filter will decide nicks will be INCLUDE ONLY.\n'
1626 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1627 ' filter will decide nicks will be EXCLUDE.\n'
1628 usage
+= s
* 2 + light_green('switch list') + \
1629 ' will switch to a Twitter list\'s stream. You will be asked for list name\n'
1638 h
, w
= os
.popen('stty size', 'r').read().split()
1641 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1642 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1643 usage
+= s
+ 'You are ' + \
1644 light_yellow('already') + ' on your personal stream.\n'
1645 usage
+= s
+ 'Any update from Twitter will show up ' + \
1646 light_yellow('immediately') + '.\n'
1647 usage
+= s
+ 'In addition, following commands are available right now:\n'
1648 # Twitter help section
1650 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1651 usage
+= s
* 2 + light_green('h discover') + \
1652 ' will show help for discover commands.\n'
1653 usage
+= s
* 2 + light_green('h tweets') + \
1654 ' will show help for tweets commands.\n'
1655 usage
+= s
* 2 + light_green('h messages') + \
1656 ' will show help for messages commands.\n'
1657 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1658 ' will show help for friends and followers commands.\n'
1659 usage
+= s
* 2 + light_green('h list') + \
1660 ' will show help for list commands.\n'
1661 usage
+= s
* 2 + light_green('h stream') + \
1662 ' will show help for stream commands.\n'
1665 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1666 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1667 'will be evaluate by Python interpreter.\n'
1668 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1669 ' for current month.\n'
1672 usage
+= s
+ grey(u
'\u266A' + ' Config \n')
1673 usage
+= s
* 2 + light_green('theme') + ' will list available theme. ' + \
1674 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1675 ' theme immediately.\n'
1676 usage
+= s
* 2 + light_green('config') + ' will list all config.\n'
1678 light_green('config ASCII_ART') + ' will output current value of ' +\
1679 light_yellow('ASCII_ART') + ' config key.\n'
1681 light_green('config TREND_MAX default') + ' will output default value of ' + \
1682 light_yellow('TREND_MAX') + ' config key.\n'
1684 light_green('config CUSTOM_CONFIG drop') + ' will drop ' + \
1685 light_yellow('CUSTOM_CONFIG') + ' config key.\n'
1687 light_green('config IMAGE_ON_TERM = true') + ' will set value of ' + \
1688 light_yellow('IMAGE_ON_TERM') + ' config key to ' + \
1689 light_yellow('True') + '.\n'
1692 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1693 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1694 usage
+= s
* 2 + light_green('p') + ' will pause the stream.\n'
1695 usage
+= s
* 2 + light_green('r') + ' will unpause the stream.\n'
1696 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1697 usage
+= s
* 2 + light_green('v') + ' will show version info.\n'
1698 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1701 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1702 usage
+= s
+ 'Have fun and hang tight! \n'
1705 'discover': help_discover
,
1706 'tweets': help_tweets
,
1707 'messages': help_messages
,
1708 'friends_and_followers': help_friends_and_followers
,
1710 'stream': help_stream
,
1715 lambda: printNicely(red('No such command.'))
1723 Pause stream display
1726 printNicely(green('Stream is paused'))
1734 printNicely(green('Stream is running back now'))
1750 printNicely(green('See you next time :)'))
1758 Reset prefix of line
1761 if c
.get('USER_JSON_ERROR'):
1762 printNicely(red('Your ~/.rainbow_config.json is messed up:'))
1763 printNicely(red('>>> ' + c
['USER_JSON_ERROR']))
1765 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1768 printNicely(str(eval(g
['cmd'])))
1822 # Handle function set
1876 return dict(zip(cmdset
, funcset
)).get(cmd
, reset
)
1881 Listen to user's input
1886 ['public', 'mine', 'list'], # switch
1895 [], # view_my_tweets
1906 ['image'], # show image
1908 ['fl', 'fr'], # list
1910 [i
for i
in g
['message_threads']], # sent
1935 [key
for key
in dict(get_all_config())], # config
1936 g
['themes'], # theme
1941 'friends_and_followers',
1952 init_interactive_shell(d
)
1959 # Only use PREFIX as a string with raw_input
1960 line
= raw_input(g
['decorated_name'](g
['PREFIX']))
1963 # Save cmd to compare with readline buffer
1964 g
['cmd'] = line
.strip()
1965 # Get short cmd to pass to handle function
1967 cmd
= line
.split()[0]
1970 # Lock the semaphore
1972 # Save cmd to global variable and call process
1973 g
['stuff'] = ' '.join(line
.split()[1:])
1974 # Check tweet length
1975 # Process the command
1978 if cmd
in ['switch', 't', 'rt', 'rep']:
1982 # Release the semaphore lock
1986 except TwitterHTTPError
as e
:
1987 detail_twitter_error(e
)
1990 printNicely(red('OMG something is wrong with Twitter API right now.'))
1993 def reconn_notice():
1995 Notice when Hangup or Timeout
1997 guide
= light_magenta('You can use ') + \
1998 light_green('switch') + \
1999 light_magenta(' command to return to your stream.\n')
2000 guide
+= light_magenta('Type ') + \
2001 light_green('h stream') + \
2002 light_magenta(' for more details.')
2004 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2008 def stream(domain
, args
, name
='Rainbow Stream'):
2014 c
['USER_DOMAIN']: name
,
2015 c
['PUBLIC_DOMAIN']: args
.track_keywords
or 'Global',
2016 c
['SITE_DOMAIN']: name
,
2019 ascii_art(art_dict
.get(domain
, name
))
2020 # These arguments are optional:
2022 timeout
=0.5, # To check g['stream_stop'] after each 0.5 s
2024 heartbeat_timeout
=c
['HEARTBEAT_TIMEOUT'] * 60)
2027 if args
.track_keywords
:
2028 query_args
['track'] = args
.track_keywords
2030 stream
= TwitterStream(
2035 if domain
== c
['USER_DOMAIN']:
2036 tweet_iter
= stream
.user(**query_args
)
2037 elif domain
== c
['SITE_DOMAIN']:
2038 tweet_iter
= stream
.site(**query_args
)
2040 if args
.track_keywords
:
2041 tweet_iter
= stream
.statuses
.filter(**query_args
)
2043 tweet_iter
= stream
.statuses
.sample()
2044 # Block new stream until other one exits
2045 StreamLock
.acquire()
2046 g
['stream_stop'] = False
2047 last_tweet_time
= time
.time()
2048 for tweet
in tweet_iter
:
2050 printNicely('-- None --')
2051 elif tweet
is Timeout
:
2052 # Because the stream check for each 0.3s
2053 # so we shouldn't output anything here
2054 if(g
['stream_stop']):
2055 StreamLock
.release()
2057 elif tweet
is HeartbeatTimeout
:
2058 printNicely('-- Heartbeat Timeout --')
2060 StreamLock
.release()
2062 elif tweet
is Hangup
:
2063 printNicely('-- Hangup --')
2065 StreamLock
.release()
2067 elif tweet
.get('text'):
2068 # Slow down the stream by STREAM_DELAY config key
2069 if time
.time() - last_tweet_time
< c
['STREAM_DELAY']:
2071 last_tweet_time
= time
.time()
2072 # Check the semaphore pause and lock (stream process only)
2080 keyword
=args
.track_keywords
,
2085 # Current readline buffer
2086 current_buffer
= readline
.get_line_buffer().strip()
2087 # There is an unexpected behaviour in MacOSX readline + Python 2:
2088 # after completely delete a word after typing it,
2089 # somehow readline buffer still contains
2090 # the 1st character of that word
2091 if current_buffer
and g
['cmd'] != current_buffer
:
2093 g
['decorated_name'](g
['PREFIX']) + current_buffer
)
2095 elif not c
['HIDE_PROMPT']:
2096 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2098 elif tweet
.get('direct_message'):
2099 # Check the semaphore pause and lock (stream process only)
2104 print_message(tweet
['direct_message'])
2105 elif tweet
.get('event'):
2106 c
['events'].append(tweet
)
2108 except TwitterHTTPError
as e
:
2111 magenta('We have connection problem with twitter stream API right now :('))
2112 detail_twitter_error(e
)
2113 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2117 magenta('There seems to be a connection problem.'))
2122 def spawn_public_stream(args
, keyword
=None):
2124 Spawn a new public stream
2126 # Only set keyword if specified
2128 if keyword
[0] == '#':
2129 keyword
= keyword
[1:]
2130 args
.track_keywords
= keyword
2131 g
['keyword'] = keyword
2133 g
['keyword'] = 'Global'
2134 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
2137 th
= threading
.Thread(
2146 def spawn_list_stream(args
, stuff
=None):
2148 Spawn a new list stream
2151 owner
, slug
= check_slug(stuff
)
2153 owner
, slug
= get_slug()
2155 # Force python 2 not redraw readline buffer
2156 listname
= '/'.join([owner
, slug
])
2157 # Set the listname variable
2158 # and reset tracked keyword
2159 g
['listname'] = listname
2161 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
2162 listname
=g
['listname']
2164 printNicely(light_yellow('getting list members ...'))
2166 t
= Twitter(auth
=authen())
2169 while next_cursor
!= 0:
2170 m
= t
.lists
.members(
2172 owner_screen_name
=owner
,
2174 include_entities
=False)
2175 for u
in m
['users']:
2176 members
.append('@' + u
['screen_name'])
2177 next_cursor
= m
['next_cursor']
2178 printNicely(light_yellow('... done.'))
2179 # Build thread filter array
2180 args
.filter = members
2182 th
= threading
.Thread(
2192 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
2194 printNicely(red('Ignore: ' + str(len(args
.ignore
)) + ' people.'))
2198 def spawn_personal_stream(args
, stuff
=None):
2200 Spawn a new personal stream
2202 # Reset the tracked keyword and listname
2203 g
['keyword'] = g
['listname'] = ''
2205 g
['PREFIX'] = u2str(emojize(format_prefix()))
2207 th
= threading
.Thread(
2212 g
['original_name']))
2222 args
= parse_arguments()
2226 # Twitter API connection problem
2227 except TwitterHTTPError
as e
:
2230 magenta('We have connection problem with twitter REST API right now :('))
2231 detail_twitter_error(e
)
2234 # Proxy connection problem
2235 except (socks
.ProxyConnectionError
, URLError
):
2237 magenta('There seems to be a connection problem.'))
2239 magenta('You might want to check your proxy settings (host, port and type)!'))
2243 # Spawn stream thread
2244 target
= args
.stream
.split()[0]
2245 if target
== 'mine':
2246 spawn_personal_stream(args
)
2249 stuff
= args
.stream
.split()[1]
2253 'public': spawn_public_stream
,
2254 'list': spawn_list_stream
,
2256 spawn_dict
.get(target
)(args
, stuff
)
2258 # Start listen process