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')
193 notice
= light_yellow('You are running latest version (')
194 notice
+= light_green(current
)
195 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
243 c
['24BIT'] = args
.color_24bit
244 # Check type of ONLY_LIST and IGNORE_LIST
245 if not isinstance(c
['ONLY_LIST'], list):
246 printNicely(red('ONLY_LIST is not a valid list value.'))
248 if not isinstance(c
['IGNORE_LIST'], list):
249 printNicely(red('IGNORE_LIST is not a valid list value.'))
250 c
['IGNORE_LIST'] = []
252 c
['IGNORE_LIST'] += build_mute_dict()
259 t
= Twitter(auth
=authen())
260 # Get country and town
262 country
= g
['stuff'].split()[0]
266 town
= g
['stuff'].split()[1]
269 avail
= t
.trends
.available()
272 trends
= t
.trends
.place(_id
=1)[0]['trends']
275 for location
in avail
:
276 # Search for country and Town
278 if location
['countryCode'] == country \
279 and location
['placeType']['name'] == 'Town' \
280 and location
['name'] == town
:
281 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
283 # Search for country only
285 if location
['countryCode'] == country \
286 and location
['placeType']['name'] == 'Country':
287 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
295 t
= Twitter(auth
=authen())
296 num
= c
['HOME_TWEET_NUM']
297 if g
['stuff'].isdigit():
298 num
= int(g
['stuff'])
299 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
309 for e
in c
['events']:
313 printNicely(magenta('Nothing at this time.'))
320 t
= Twitter(auth
=authen())
321 num
= c
['HOME_TWEET_NUM']
322 if g
['stuff'].isdigit():
323 num
= int(g
['stuff'])
324 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
331 Show profile of a specific user
333 t
= Twitter(auth
=authen())
335 screen_name
= g
['stuff'].split()[0]
337 printNicely(red('Sorry I can\'t understand.'))
339 if screen_name
.startswith('@'):
342 screen_name
=screen_name
[1:],
343 include_entities
=False)
347 printNicely(red('No user.'))
349 printNicely(red('A name should begin with a \'@\''))
356 t
= Twitter(auth
=authen())
358 user
= g
['stuff'].split()[0]
360 printNicely(red('Sorry I can\'t understand.'))
364 num
= int(g
['stuff'].split()[1])
366 num
= c
['HOME_TWEET_NUM']
367 for tweet
in reversed(
368 t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
372 printNicely(red('A name should begin with a \'@\''))
375 def view_my_tweets():
377 Display user's recent tweets.
379 t
= Twitter(auth
=authen())
381 num
= int(g
['stuff'])
383 num
= c
['HOME_TWEET_NUM']
384 for tweet
in reversed(
385 t
.statuses
.user_timeline(count
=num
, screen_name
=g
['original_name'])):
394 t
= Twitter(auth
=authen())
396 query
= g
['stuff'].strip()
398 printNicely(red('Sorry I can\'t understand.'))
400 type = c
['SEARCH_TYPE']
401 if type not in ['mixed', 'recent', 'popular']:
403 max_record
= c
['SEARCH_MAX_RECORD']
404 count
= min(max_record
, 100)
406 rel
= t
.search
.tweets(
413 printNicely('Newest tweets:')
414 for i
in reversed(xrange(count
)):
415 draw(t
=rel
[i
], keyword
=query
)
418 printNicely(magenta('I\'m afraid there is no result'))
425 t
= Twitter(auth
=authen())
426 t
.statuses
.update(status
=g
['stuff'])
433 t
= Twitter(auth
=authen())
435 id = int(g
['stuff'].split()[0])
437 printNicely(red('Sorry I can\'t understand.'))
439 tid
= c
['tweet_dict'][id]
440 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
448 t
= Twitter(auth
=authen())
450 id = int(g
['stuff'].split()[0])
452 printNicely(red('Sorry I can\'t understand.'))
454 tid
= c
['tweet_dict'][id]
455 tweet
= t
.statuses
.show(id=tid
)
457 formater
= format_quote(tweet
)
461 prefix
= light_magenta('Compose your ', rl
=True) + \
462 light_green('#comment: ', rl
=True)
463 comment
= raw_input(prefix
)
465 quote
= comment
.join(formater
.split('#comment'))
466 t
.statuses
.update(status
=quote
)
468 printNicely(light_magenta('No text added.'))
475 t
= Twitter(auth
=authen())
478 id = int(g
['stuff'].split()[0])
480 printNicely(red('Sorry I can\'t understand.'))
482 tid
= c
['tweet_dict'][id]
483 # Get display num if exist
485 num
= int(g
['stuff'].split()[1])
487 num
= c
['RETWEETS_SHOW_NUM']
488 # Get result and display
489 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
491 printNicely(magenta('This tweet has no retweet.'))
493 for tweet
in reversed(rt_ary
):
502 t
= Twitter(auth
=authen())
504 id = int(g
['stuff'].split()[0])
506 printNicely(red('Sorry I can\'t understand.'))
508 tid
= c
['tweet_dict'][id]
509 tweet
= t
.statuses
.show(id=tid
)
510 limit
= c
['CONVERSATION_MAX']
512 thread_ref
.append(tweet
)
513 prev_tid
= tweet
['in_reply_to_status_id']
514 while prev_tid
and limit
:
516 tweet
= t
.statuses
.show(id=prev_tid
)
517 prev_tid
= tweet
['in_reply_to_status_id']
518 thread_ref
.append(tweet
)
520 for tweet
in reversed(thread_ref
):
529 t
= Twitter(auth
=authen())
531 id = int(g
['stuff'].split()[0])
533 printNicely(red('Sorry I can\'t understand.'))
535 tid
= c
['tweet_dict'][id]
536 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
537 status
= ' '.join(g
['stuff'].split()[1:])
538 status
= '@' + user
+ ' ' + str2u(status
)
539 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
546 t
= Twitter(auth
=authen())
548 id = int(g
['stuff'].split()[0])
550 printNicely(red('Sorry I can\'t understand.'))
552 tid
= c
['tweet_dict'][id]
553 original_tweet
= t
.statuses
.show(id=tid
)
554 text
= original_tweet
['text']
555 nick_ary
= [original_tweet
['user']['screen_name']]
556 for user
in list(original_tweet
['entities']['user_mentions']):
557 if user
['screen_name'] not in nick_ary \
558 and user
['screen_name'] != g
['original_name']:
559 nick_ary
.append(user
['screen_name'])
560 status
= ' '.join(g
['stuff'].split()[1:])
561 status
= ' '.join(['@' + nick
for nick
in nick_ary
]) + ' ' + str2u(status
)
562 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
569 t
= Twitter(auth
=authen())
571 id = int(g
['stuff'].split()[0])
573 printNicely(red('Sorry I can\'t understand.'))
575 tid
= c
['tweet_dict'][id]
576 t
.favorites
.create(_id
=tid
, include_entities
=False)
577 printNicely(green('Favorited.'))
578 draw(t
.statuses
.show(id=tid
))
586 t
= Twitter(auth
=authen())
588 id = int(g
['stuff'].split()[0])
590 printNicely(red('Sorry I can\'t understand.'))
592 tid
= c
['tweet_dict'][id]
593 t
.favorites
.destroy(_id
=tid
)
594 printNicely(green('Okay it\'s unfavorited.'))
595 draw(t
.statuses
.show(id=tid
))
601 Copy url of a tweet to clipboard
603 t
= Twitter(auth
=authen())
605 id = int(g
['stuff'].split()[0])
606 tid
= c
['tweet_dict'][id]
608 printNicely(red('Tweet id is not valid.'))
610 tweet
= t
.statuses
.show(id=tid
)
611 url
= 'https://twitter.com/' + \
612 tweet
['user']['screen_name'] + '/status/' + str(tid
)
614 if platform
.system().lower() == 'darwin':
615 os
.system("echo '%s' | pbcopy" % url
)
616 printNicely(green('Copied tweet\'s url to clipboard.'))
618 printNicely('Direct link: ' + yellow(url
))
625 t
= Twitter(auth
=authen())
627 id = int(g
['stuff'].split()[0])
629 printNicely(red('Sorry I can\'t understand.'))
631 tid
= c
['tweet_dict'][id]
632 t
.statuses
.destroy(id=tid
)
633 printNicely(green('Okay it\'s gone.'))
640 t
= Twitter(auth
=authen())
642 target
= g
['stuff'].split()[0]
643 if target
!= 'image':
645 id = int(g
['stuff'].split()[1])
646 tid
= c
['tweet_dict'][id]
647 tweet
= t
.statuses
.show(id=tid
)
648 media
= tweet
['entities']['media']
650 res
= requests
.get(m
['media_url'])
651 img
= Image
.open(BytesIO(res
.content
))
655 printNicely(red('Sorry I can\'t show this image.'))
662 t
= Twitter(auth
=authen())
664 if not g
['stuff'].isdigit():
666 tid
= c
['tweet_dict'][int(g
['stuff'])]
667 tweet
= t
.statuses
.show(id=tid
)
668 urls
= tweet
['entities']['urls']
670 printNicely(light_magenta('No url here @.@!'))
674 expanded_url
= url
['expanded_url']
675 webbrowser
.open(expanded_url
)
678 printNicely(red('Sorry I can\'t open url in this tweet.'))
685 t
= Twitter(auth
=authen())
686 num
= c
['MESSAGES_DISPLAY']
687 if g
['stuff'].isdigit():
693 inbox
= inbox
+ t
.direct_messages(
696 include_entities
=False,
701 inbox
= inbox
+ t
.direct_messages(
704 include_entities
=False,
708 num
= c
['MESSAGES_DISPLAY']
709 if g
['stuff'].isdigit():
714 sent
= sent
+ t
.direct_messages
.sent(
717 include_entities
=False,
722 sent
= sent
+ t
.direct_messages
.sent(
725 include_entities
=False,
730 uniq_inbox
= list(set(
731 [(m
['sender_screen_name'], m
['sender']['name']) for m
in inbox
]
733 uniq_sent
= list(set(
734 [(m
['recipient_screen_name'], m
['recipient']['name']) for m
in sent
]
736 for partner
in uniq_inbox
:
737 inbox_ary
= [m
for m
in inbox
if m
['sender_screen_name'] == partner
[0]]
739 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
740 d
[partner
] = inbox_ary
+ sent_ary
741 for partner
in uniq_sent
:
744 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
745 g
['message_threads'] = print_threads(d
)
750 View a thread of message
753 thread_id
= int(g
['stuff'])
755 g
['message_threads'][thread_id
],
760 printNicely(red('No such thread.'))
765 Send a direct message
767 t
= Twitter(auth
=authen())
769 user
= g
['stuff'].split()[0]
770 if user
[0].startswith('@'):
771 content
= ' '.join(g
['stuff'].split()[1:])
772 t
.direct_messages
.new(
773 screen_name
=user
[1:],
776 printNicely(green('Message sent.'))
778 printNicely(red('A name should begin with a \'@\''))
781 printNicely(red('Sorry I can\'t understand.'))
788 t
= Twitter(auth
=authen())
790 id = int(g
['stuff'].split()[0])
792 printNicely(red('Sorry I can\'t understand.'))
793 mid
= c
['message_dict'][id]
794 t
.direct_messages
.destroy(id=mid
)
795 printNicely(green('Message deleted.'))
800 List friends for followers
802 t
= Twitter(auth
=authen())
805 name
= g
['stuff'].split()[1]
806 if name
.startswith('@'):
809 printNicely(red('A name should begin with a \'@\''))
810 raise Exception('Invalid name')
812 name
= g
['original_name']
813 # Get list followers or friends
815 target
= g
['stuff'].split()[0]
817 printNicely(red('Omg some syntax is wrong.'))
820 d
= {'fl': 'followers', 'fr': 'friends'}
824 while next_cursor
!= 0:
825 list = getattr(t
, d
[target
]).list(
829 include_entities
=False,
831 for u
in list['users']:
832 rel
[u
['name']] = '@' + u
['screen_name']
833 next_cursor
= list['next_cursor']
835 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
837 user
= ' ' + cycle_color(name
)
838 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
846 t
= Twitter(auth
=authen())
847 screen_name
= g
['stuff'].split()[0]
848 if screen_name
.startswith('@'):
849 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
850 printNicely(green('You are following ' + screen_name
+ ' now!'))
852 printNicely(red('A name should begin with a \'@\''))
859 t
= Twitter(auth
=authen())
860 screen_name
= g
['stuff'].split()[0]
861 if screen_name
.startswith('@'):
862 t
.friendships
.destroy(
863 screen_name
=screen_name
[1:],
864 include_entities
=False)
865 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
867 printNicely(red('A name should begin with a \'@\''))
874 t
= Twitter(auth
=authen())
876 screen_name
= g
['stuff'].split()[0]
878 printNicely(red('A name should be specified. '))
880 if screen_name
.startswith('@'):
882 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
883 if isinstance(rel
, dict):
884 printNicely(green(screen_name
+ ' is muted.'))
885 c
['IGNORE_LIST'] += [screen_name
]
886 c
['IGNORE_LIST'] = list(set(c
['IGNORE_LIST']))
888 printNicely(red(rel
))
891 printNicely(red('Something is wrong, can not mute now :('))
893 printNicely(red('A name should begin with a \'@\''))
900 t
= Twitter(auth
=authen())
902 screen_name
= g
['stuff'].split()[0]
904 printNicely(red('A name should be specified. '))
906 if screen_name
.startswith('@'):
908 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
909 if isinstance(rel
, dict):
910 printNicely(green(screen_name
+ ' is unmuted.'))
911 c
['IGNORE_LIST'].remove(screen_name
)
913 printNicely(red(rel
))
915 printNicely(red('Maybe you are not muting this person ?'))
917 printNicely(red('A name should begin with a \'@\''))
924 # Get dict of muting users
925 md
= build_mute_dict(dict_data
=True)
926 printNicely('All: ' + str(len(md
)) + ' people.')
928 user
= ' ' + cycle_color(md
[name
])
929 user
+= color_func(c
['TWEET']['nick'])(' ' + name
+ ' ')
931 # Update from Twitter
932 c
['IGNORE_LIST'] = [n
for n
in md
]
939 t
= Twitter(auth
=authen())
940 screen_name
= g
['stuff'].split()[0]
941 if screen_name
.startswith('@'):
943 screen_name
=screen_name
[1:],
944 include_entities
=False,
946 printNicely(green('You blocked ' + screen_name
+ '.'))
948 printNicely(red('A name should begin with a \'@\''))
955 t
= Twitter(auth
=authen())
956 screen_name
= g
['stuff'].split()[0]
957 if screen_name
.startswith('@'):
959 screen_name
=screen_name
[1:],
960 include_entities
=False,
962 printNicely(green('Unblock ' + screen_name
+ ' success!'))
964 printNicely(red('A name should begin with a \'@\''))
969 Report a user as a spam account
971 t
= Twitter(auth
=authen())
972 screen_name
= g
['stuff'].split()[0]
973 if screen_name
.startswith('@'):
975 screen_name
=screen_name
[1:])
976 printNicely(green('You reported ' + screen_name
+ '.'))
978 printNicely(red('Sorry I can\'t understand.'))
986 list_name
= raw_input(
987 light_magenta('Give me the list\'s name ("@owner/list_name"): ', rl
=True))
988 # Get list name and owner
990 owner
, slug
= list_name
.split('/')
991 if slug
.startswith('@'):
996 light_magenta('List name should follow "@owner/list_name" format.'))
997 raise Exception('Wrong list name')
1000 def check_slug(list_name
):
1004 # Get list name and owner
1006 owner
, slug
= list_name
.split('/')
1007 if slug
.startswith('@'):
1012 light_magenta('List name should follow "@owner/list_name" format.'))
1013 raise Exception('Wrong list name')
1020 rel
= t
.lists
.list(screen_name
=g
['original_name'])
1024 printNicely(light_magenta('You belong to no lists :)'))
1031 owner
, slug
= get_slug()
1032 res
= t
.lists
.statuses(
1034 owner_screen_name
=owner
,
1035 count
=c
['LIST_MAX'],
1036 include_entities
=False)
1037 for tweet
in reversed(res
):
1042 def list_members(t
):
1046 owner
, slug
= get_slug()
1050 while next_cursor
!= 0:
1051 m
= t
.lists
.members(
1053 owner_screen_name
=owner
,
1055 include_entities
=False)
1056 for u
in m
['users']:
1057 rel
[u
['name']] = '@' + u
['screen_name']
1058 next_cursor
= m
['next_cursor']
1059 printNicely('All: ' + str(len(rel
)) + ' members.')
1061 user
= ' ' + cycle_color(name
)
1062 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1066 def list_subscribers(t
):
1070 owner
, slug
= get_slug()
1074 while next_cursor
!= 0:
1075 m
= t
.lists
.subscribers(
1077 owner_screen_name
=owner
,
1079 include_entities
=False)
1080 for u
in m
['users']:
1081 rel
[u
['name']] = '@' + u
['screen_name']
1082 next_cursor
= m
['next_cursor']
1083 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
1085 user
= ' ' + cycle_color(name
)
1086 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1092 Add specific user to a list
1094 owner
, slug
= get_slug()
1096 user_name
= raw_input(
1098 'Give me name of the newbie: ',
1100 if user_name
.startswith('@'):
1101 user_name
= user_name
[1:]
1103 t
.lists
.members
.create(
1105 owner_screen_name
=owner
,
1106 screen_name
=user_name
)
1107 printNicely(green('Added.'))
1110 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
1115 Remove specific user from a list
1117 owner
, slug
= get_slug()
1119 user_name
= raw_input(
1121 'Give me name of the unlucky one: ',
1123 if user_name
.startswith('@'):
1124 user_name
= user_name
[1:]
1126 t
.lists
.members
.destroy(
1128 owner_screen_name
=owner
,
1129 screen_name
=user_name
)
1130 printNicely(green('Gone.'))
1133 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
1136 def list_subscribe(t
):
1140 owner
, slug
= get_slug()
1143 t
.lists
.subscribers
.create(
1145 owner_screen_name
=owner
)
1146 printNicely(green('Done.'))
1150 light_magenta('I\'m sorry you can not subscribe to this list.'))
1153 def list_unsubscribe(t
):
1157 owner
, slug
= get_slug()
1160 t
.lists
.subscribers
.destroy(
1162 owner_screen_name
=owner
)
1163 printNicely(green('Done.'))
1167 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
1176 while next_cursor
!= 0:
1177 res
= t
.lists
.ownerships(
1178 screen_name
=g
['original_name'],
1181 next_cursor
= res
['next_cursor']
1185 printNicely(light_magenta('You own no lists :)'))
1192 name
= raw_input(light_magenta('New list\'s name: ', rl
=True))
1195 'New list\'s mode (public/private): ',
1197 description
= raw_input(
1199 'New list\'s description: ',
1205 description
=description
)
1206 printNicely(green(name
+ ' list is created.'))
1209 printNicely(red('Oops something is wrong with Twitter :('))
1218 'Your list that you want to update: ',
1222 'Update name (leave blank to unchange): ',
1224 mode
= raw_input(light_magenta('Update mode (public/private): ', rl
=True))
1225 description
= raw_input(light_magenta('Update description: ', rl
=True))
1229 slug
='-'.join(slug
.split()),
1230 owner_screen_name
=g
['original_name'],
1233 description
=description
)
1237 owner_screen_name
=g
['original_name'],
1239 description
=description
)
1240 printNicely(green(slug
+ ' list is updated.'))
1243 printNicely(red('Oops something is wrong with Twitter :('))
1252 'Your list that you want to delete: ',
1256 slug
='-'.join(slug
.split()),
1257 owner_screen_name
=g
['original_name'])
1258 printNicely(green(slug
+ ' list is deleted.'))
1261 printNicely(red('Oops something is wrong with Twitter :('))
1268 t
= Twitter(auth
=authen())
1269 # List all lists or base on action
1271 g
['list_action'] = g
['stuff'].split()[0]
1278 'all_mem': list_members
,
1279 'all_sub': list_subscribers
,
1282 'sub': list_subscribe
,
1283 'unsub': list_unsubscribe
,
1286 'update': list_update
,
1290 return action_ary
[g
['list_action']](t
)
1292 printNicely(red('Please try again.'))
1300 target
= g
['stuff'].split()[0]
1302 args
= parse_arguments()
1304 if g
['stuff'].split()[-1] == '-f':
1305 guide
= 'To ignore an option, just hit Enter key.'
1306 printNicely(light_magenta(guide
))
1307 only
= raw_input('Only nicks [Ex: @xxx,@yy]: ')
1308 ignore
= raw_input('Ignore nicks [Ex: @xxx,@yy]: ')
1309 args
.filter = filter(None, only
.split(','))
1310 args
.ignore
= filter(None, ignore
.split(','))
1312 printNicely(red('Sorry, wrong format.'))
1315 g
['stream_stop'] = True
1317 stuff
= g
['stuff'].split()[1]
1322 'public': spawn_public_stream
,
1323 'list': spawn_list_stream
,
1324 'mine': spawn_personal_stream
,
1326 spawn_dict
.get(target
)(args
, stuff
)
1329 printNicely(red('Sorry I can\'t understand.'))
1334 Unix's command `cal`
1337 rel
= os
.popen('cal').read().split('\n')
1340 show_calendar(month
, date
, rel
)
1345 List and change theme
1349 for theme
in g
['themes']:
1350 line
= light_magenta(theme
)
1351 if c
['THEME'] == theme
:
1352 line
= ' ' * 2 + light_yellow('* ') + line
1354 line
= ' ' * 4 + line
1360 c
['THEME'] = reload_theme(g
['stuff'], c
['THEME'])
1361 # Redefine decorated_name
1362 g
['decorated_name'] = lambda x
: color_func(
1363 c
['DECORATED_NAME'])(
1365 printNicely(green('Theme changed.'))
1367 printNicely(red('No such theme exists.'))
1372 Browse and change config
1374 all_config
= get_all_config()
1375 g
['stuff'] = g
['stuff'].strip()
1378 for k
in all_config
:
1380 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1382 guide
= 'Detailed explanation can be found at ' + \
1383 color_func(c
['TWEET']['link'])(
1384 'http://rainbowstream.readthedocs.org/en/latest/#config-explanation')
1386 # Print specific config
1387 elif len(g
['stuff'].split()) == 1:
1388 if g
['stuff'] in all_config
:
1391 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1394 printNicely(red('No such config key.'))
1395 # Print specific config's default value
1396 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'default':
1397 key
= g
['stuff'].split()[0]
1399 value
= get_default_config(key
)
1400 line
= ' ' * 2 + green(key
) + ': ' + light_magenta(value
)
1404 printNicely(red('Just can not get the default.'))
1405 # Delete specific config key in config file
1406 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'drop':
1407 key
= g
['stuff'].split()[0]
1410 printNicely(green('Config key is dropped.'))
1413 printNicely(red('Just can not drop the key.'))
1414 # Set specific config
1415 elif len(g
['stuff'].split()) == 3 and g
['stuff'].split()[1] == '=':
1416 key
= g
['stuff'].split()[0]
1417 value
= g
['stuff'].split()[-1]
1418 if key
== 'THEME' and not validate_theme(value
):
1419 printNicely(red('Invalid theme\'s value.'))
1422 set_config(key
, value
)
1423 # Keys that needs to be apply immediately
1425 c
['THEME'] = reload_theme(value
, c
['THEME'])
1426 g
['decorated_name'] = lambda x
: color_func(
1427 c
['DECORATED_NAME'])('[' + x
+ ']: ')
1428 elif key
== 'PREFIX':
1429 g
['PREFIX'] = u2str(emojize(format_prefix(
1430 listname
=g
['listname'],
1431 keyword
=g
['keyword']
1434 printNicely(green('Updated successfully.'))
1437 printNicely(red('Just can not set the key.'))
1439 printNicely(light_magenta('Sorry I can\'s understand.'))
1442 def help_discover():
1447 # Discover the world
1449 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1450 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1451 'You can try ' + light_green('trend US') + ' or ' + \
1452 light_green('trend JP Tokyo') + '.\n'
1453 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1454 light_green('home 7') + ' will show 7 tweets.\n'
1455 usage
+= s
* 2 + light_green('me') + ' will show your latest tweets. ' + \
1456 light_green('me 2') + ' will show your last 2 tweets.\n'
1458 light_green('notification') + ' will show your recent notification.\n'
1459 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1460 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1461 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1462 magenta('@mdo') + '.\n'
1463 usage
+= s
* 2 + light_green('view @mdo') + \
1464 ' will show ' + magenta('@mdo') + '\'s home.\n'
1465 usage
+= s
* 2 + light_green('s AKB48') + ' will search for "' + \
1466 light_yellow('AKB48') + '" and return 5 newest tweet. ' + \
1467 'Search can be performed with or without hashtag.\n'
1478 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1479 usage
+= s
* 2 + light_green('t oops ') + \
1480 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1482 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1483 light_yellow('[id=12]') + '.\n'
1485 light_green('quote 12 ') + ' will quote the tweet with ' + \
1486 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1487 'the quote will be canceled.\n'
1489 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1490 light_yellow('[id=12]') + '.\n'
1491 usage
+= s
* 2 + light_green('conversation 12') + ' will show the chain of ' + \
1492 'replies prior to the tweet with ' + light_yellow('[id=12]') + '.\n'
1493 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1494 light_yellow('oops') + '" to the owner of the tweet with ' + \
1495 light_yellow('[id=12]') + '.\n'
1496 usage
+= s
* 2 + light_green('repall 12 oops') + ' will reply "' + \
1497 light_yellow('oops') + '" to all people in the tweet with ' + \
1498 light_yellow('[id=12]') + '.\n'
1500 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1501 light_yellow('[id=12]') + '.\n'
1503 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1504 light_yellow('[id=12]') + '.\n'
1506 light_green('share 12 ') + ' will get the direct link of the tweet with ' + \
1507 light_yellow('[id=12]') + '.\n'
1509 light_green('del 12 ') + ' will delete tweet with ' + \
1510 light_yellow('[id=12]') + '.\n'
1511 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1512 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1513 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1514 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1518 def help_messages():
1525 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1526 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1527 light_green('inbox 7') + ' will show newest 7 messages.\n'
1528 usage
+= s
* 2 + light_green('thread 2') + ' will show full thread with ' + \
1529 light_yellow('[thread_id=2]') + '.\n'
1530 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1531 magenta('@dtvd88') + '.\n'
1532 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1533 light_yellow('[message_id=5]') + '.\n'
1537 def help_friends_and_followers():
1539 Friends and Followers
1542 # Follower and following
1544 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1546 light_green('ls fl') + \
1547 ' will list all followers (people who are following you).\n'
1549 light_green('ls fr') + \
1550 ' will list all friends (people who you are following).\n'
1551 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1552 magenta('@dtvd88') + '.\n'
1553 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1554 magenta('@dtvd88') + '.\n'
1555 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1556 magenta('@dtvd88') + '.\n'
1557 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1558 magenta('@dtvd88') + '.\n'
1559 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1560 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1561 magenta('@dtvd88') + '.\n'
1562 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1563 magenta('@dtvd88') + '.\n'
1564 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1565 magenta('@dtvd88') + ' as a spam account.\n'
1576 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1577 usage
+= s
* 2 + light_green('list') + \
1578 ' will show all lists you are belong to.\n'
1579 usage
+= s
* 2 + light_green('list home') + \
1580 ' will show timeline of list. You will be asked for list\'s name.\n'
1581 usage
+= s
* 2 + light_green('list all_mem') + \
1582 ' will show list\'s all members.\n'
1583 usage
+= s
* 2 + light_green('list all_sub') + \
1584 ' will show list\'s all subscribers.\n'
1585 usage
+= s
* 2 + light_green('list add') + \
1586 ' will add specific person to a list owned by you.' + \
1587 ' You will be asked for list\'s name and person\'s name.\n'
1588 usage
+= s
* 2 + light_green('list rm') + \
1589 ' will remove specific person from 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 sub') + \
1592 ' will subscribe you to a specific list.\n'
1593 usage
+= s
* 2 + light_green('list unsub') + \
1594 ' will unsubscribe you from a specific list.\n'
1595 usage
+= s
* 2 + light_green('list own') + \
1596 ' will show all list owned by you.\n'
1597 usage
+= s
* 2 + light_green('list new') + \
1598 ' will create a new list.\n'
1599 usage
+= s
* 2 + light_green('list update') + \
1600 ' will update a list owned by you.\n'
1601 usage
+= s
* 2 + light_green('list del') + \
1602 ' will delete a list owned by you.\n'
1613 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1614 usage
+= s
* 2 + light_green('switch public #AKB') + \
1615 ' will switch to public stream and follow "' + \
1616 light_yellow('AKB') + '" keyword.\n'
1617 usage
+= s
* 2 + light_green('switch mine') + \
1618 ' will switch to your personal stream.\n'
1619 usage
+= s
* 2 + light_green('switch mine -f ') + \
1620 ' will prompt to enter the filter.\n'
1621 usage
+= s
* 3 + light_yellow('Only nicks') + \
1622 ' filter will decide nicks will be INCLUDE ONLY.\n'
1623 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1624 ' filter will decide nicks will be EXCLUDE.\n'
1625 usage
+= s
* 2 + light_green('switch list') + \
1626 ' will switch to a Twitter list\'s stream. You will be asked for list name\n'
1635 h
, w
= os
.popen('stty size', 'r').read().split()
1638 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1639 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1640 usage
+= s
+ 'You are ' + \
1641 light_yellow('already') + ' on your personal stream.\n'
1642 usage
+= s
+ 'Any update from Twitter will show up ' + \
1643 light_yellow('immediately') + '.\n'
1644 usage
+= s
+ 'In addition, following commands are available right now:\n'
1645 # Twitter help section
1647 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1648 usage
+= s
* 2 + light_green('h discover') + \
1649 ' will show help for discover commands.\n'
1650 usage
+= s
* 2 + light_green('h tweets') + \
1651 ' will show help for tweets commands.\n'
1652 usage
+= s
* 2 + light_green('h messages') + \
1653 ' will show help for messages commands.\n'
1654 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1655 ' will show help for friends and followers commands.\n'
1656 usage
+= s
* 2 + light_green('h list') + \
1657 ' will show help for list commands.\n'
1658 usage
+= s
* 2 + light_green('h stream') + \
1659 ' will show help for stream commands.\n'
1662 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1663 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1664 'will be evaluate by Python interpreter.\n'
1665 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1666 ' for current month.\n'
1669 usage
+= s
+ grey(u
'\u266A' + ' Config \n')
1670 usage
+= s
* 2 + light_green('theme') + ' will list available theme. ' + \
1671 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1672 ' theme immediately.\n'
1673 usage
+= s
* 2 + light_green('config') + ' will list all config.\n'
1675 light_green('config ASCII_ART') + ' will output current value of ' +\
1676 light_yellow('ASCII_ART') + ' config key.\n'
1678 light_green('config TREND_MAX default') + ' will output default value of ' + \
1679 light_yellow('TREND_MAX') + ' config key.\n'
1681 light_green('config CUSTOM_CONFIG drop') + ' will drop ' + \
1682 light_yellow('CUSTOM_CONFIG') + ' config key.\n'
1684 light_green('config IMAGE_ON_TERM = true') + ' will set value of ' + \
1685 light_yellow('IMAGE_ON_TERM') + ' config key to ' + \
1686 light_yellow('True') + '.\n'
1689 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1690 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1691 usage
+= s
* 2 + light_green('p') + ' will pause the stream.\n'
1692 usage
+= s
* 2 + light_green('r') + ' will unpause the stream.\n'
1693 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1694 usage
+= s
* 2 + light_green('v') + ' will show version info.\n'
1695 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1698 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1699 usage
+= s
+ 'Have fun and hang tight! \n'
1702 'discover': help_discover
,
1703 'tweets': help_tweets
,
1704 'messages': help_messages
,
1705 'friends_and_followers': help_friends_and_followers
,
1707 'stream': help_stream
,
1712 lambda: printNicely(red('No such command.'))
1720 Pause stream display
1723 printNicely(green('Stream is paused'))
1731 printNicely(green('Stream is running back now'))
1747 printNicely(green('See you next time :)'))
1755 Reset prefix of line
1758 if c
.get('USER_JSON_ERROR'):
1759 printNicely(red('Your ~/.rainbow_config.json is messed up:'))
1760 printNicely(red('>>> ' + c
['USER_JSON_ERROR']))
1762 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1765 printNicely(str(eval(g
['cmd'])))
1819 # Handle function set
1873 return dict(zip(cmdset
, funcset
)).get(cmd
, reset
)
1878 Listen to user's input
1883 ['public', 'mine', 'list'], # switch
1892 [], # view_my_tweets
1903 ['image'], # show image
1905 ['fl', 'fr'], # list
1907 [i
for i
in g
['message_threads']], # sent
1932 [key
for key
in dict(get_all_config())], # config
1933 g
['themes'], # theme
1938 'friends_and_followers',
1949 init_interactive_shell(d
)
1956 # Only use PREFIX as a string with raw_input
1957 line
= raw_input(g
['decorated_name'](g
['PREFIX']))
1960 # Save cmd to compare with readline buffer
1961 g
['cmd'] = line
.strip()
1962 # Get short cmd to pass to handle function
1964 cmd
= line
.split()[0]
1967 # Lock the semaphore
1969 # Save cmd to global variable and call process
1970 g
['stuff'] = ' '.join(line
.split()[1:])
1971 # Check tweet length
1972 # Process the command
1975 if cmd
in ['switch', 't', 'rt', 'rep']:
1981 except TwitterHTTPError
as e
:
1982 detail_twitter_error(e
)
1985 printNicely(red('OMG something is wrong with Twitter API right now.'))
1987 # Release the semaphore lock
1991 def reconn_notice():
1993 Notice when Hangup or Timeout
1995 guide
= light_magenta('You can use ') + \
1996 light_green('switch') + \
1997 light_magenta(' command to return to your stream.\n')
1998 guide
+= light_magenta('Type ') + \
1999 light_green('h stream') + \
2000 light_magenta(' for more details.')
2002 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2006 def stream(domain
, args
, name
='Rainbow Stream'):
2012 c
['USER_DOMAIN']: name
,
2013 c
['PUBLIC_DOMAIN']: args
.track_keywords
or 'Global',
2014 c
['SITE_DOMAIN']: name
,
2017 ascii_art(art_dict
.get(domain
, name
))
2018 # These arguments are optional:
2020 timeout
=0.5, # To check g['stream_stop'] after each 0.5 s
2022 heartbeat_timeout
=c
['HEARTBEAT_TIMEOUT'] * 60)
2025 if args
.track_keywords
:
2026 query_args
['track'] = args
.track_keywords
2028 stream
= TwitterStream(
2033 if domain
== c
['USER_DOMAIN']:
2034 tweet_iter
= stream
.user(**query_args
)
2035 elif domain
== c
['SITE_DOMAIN']:
2036 tweet_iter
= stream
.site(**query_args
)
2038 if args
.track_keywords
:
2039 tweet_iter
= stream
.statuses
.filter(**query_args
)
2041 tweet_iter
= stream
.statuses
.sample()
2042 # Block new stream until other one exits
2043 StreamLock
.acquire()
2044 g
['stream_stop'] = False
2045 last_tweet_time
= time
.time()
2046 for tweet
in tweet_iter
:
2048 printNicely('-- None --')
2049 elif tweet
is Timeout
:
2050 # Because the stream check for each 0.3s
2051 # so we shouldn't output anything here
2052 if(g
['stream_stop']):
2053 StreamLock
.release()
2055 elif tweet
is HeartbeatTimeout
:
2056 printNicely('-- Heartbeat Timeout --')
2058 StreamLock
.release()
2060 elif tweet
is Hangup
:
2061 printNicely('-- Hangup --')
2063 StreamLock
.release()
2065 elif tweet
.get('text'):
2066 # Slow down the stream by STREAM_DELAY config key
2067 if time
.time() - last_tweet_time
< c
['STREAM_DELAY']:
2069 last_tweet_time
= time
.time()
2070 # Check the semaphore pause and lock (stream process only)
2078 keyword
=args
.track_keywords
,
2083 # Current readline buffer
2084 current_buffer
= readline
.get_line_buffer().strip()
2085 # There is an unexpected behaviour in MacOSX readline + Python 2:
2086 # after completely delete a word after typing it,
2087 # somehow readline buffer still contains
2088 # the 1st character of that word
2089 if current_buffer
and g
['cmd'] != current_buffer
:
2091 g
['decorated_name'](g
['PREFIX']) + current_buffer
)
2093 elif not c
['HIDE_PROMPT']:
2094 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2096 elif tweet
.get('direct_message'):
2097 # Check the semaphore pause and lock (stream process only)
2102 print_message(tweet
['direct_message'])
2103 elif tweet
.get('event'):
2104 c
['events'].append(tweet
)
2106 except TwitterHTTPError
as e
:
2109 magenta('We have connection problem with twitter stream API right now :('))
2110 detail_twitter_error(e
)
2111 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2115 magenta('There seems to be a connection problem.'))
2120 def spawn_public_stream(args
, keyword
=None):
2122 Spawn a new public stream
2124 # Only set keyword if specified
2126 if keyword
[0] == '#':
2127 keyword
= keyword
[1:]
2128 args
.track_keywords
= keyword
2129 g
['keyword'] = keyword
2131 g
['keyword'] = 'Global'
2132 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
2135 th
= threading
.Thread(
2144 def spawn_list_stream(args
, stuff
=None):
2146 Spawn a new list stream
2149 owner
, slug
= check_slug(stuff
)
2151 owner
, slug
= get_slug()
2153 # Force python 2 not redraw readline buffer
2154 listname
= '/'.join([owner
, slug
])
2155 # Set the listname variable
2156 # and reset tracked keyword
2157 g
['listname'] = listname
2159 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
2160 listname
=g
['listname']
2162 printNicely(light_yellow('getting list members ...'))
2164 t
= Twitter(auth
=authen())
2167 while next_cursor
!= 0:
2168 m
= t
.lists
.members(
2170 owner_screen_name
=owner
,
2172 include_entities
=False)
2173 for u
in m
['users']:
2174 members
.append('@' + u
['screen_name'])
2175 next_cursor
= m
['next_cursor']
2176 printNicely(light_yellow('... done.'))
2177 # Build thread filter array
2178 args
.filter = members
2180 th
= threading
.Thread(
2190 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
2192 printNicely(red('Ignore: ' + str(len(args
.ignore
)) + ' people.'))
2196 def spawn_personal_stream(args
, stuff
=None):
2198 Spawn a new personal stream
2200 # Reset the tracked keyword and listname
2201 g
['keyword'] = g
['listname'] = ''
2203 g
['PREFIX'] = u2str(emojize(format_prefix()))
2205 th
= threading
.Thread(
2210 g
['original_name']))
2220 args
= parse_arguments()
2224 # Twitter API connection problem
2225 except TwitterHTTPError
as e
:
2228 magenta('We have connection problem with twitter REST API right now :('))
2229 detail_twitter_error(e
)
2232 # Proxy connection problem
2233 except (socks
.ProxyConnectionError
, URLError
):
2235 magenta('There seems to be a connection problem.'))
2237 magenta('You might want to check your proxy settings (host, port and type)!'))
2241 # Spawn stream thread
2242 target
= args
.stream
.split()[0]
2243 if target
== 'mine':
2244 spawn_personal_stream(args
)
2247 stuff
= args
.stream
.split()[1]
2251 'public': spawn_public_stream
,
2252 'list': spawn_list_stream
,
2254 spawn_dict
.get(target
)(args
, stuff
)
2256 # Start listen process