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 \'@\''))
382 t
= Twitter(auth
=authen())
384 query
= g
['stuff'].strip()
386 printNicely(red('Sorry I can\'t understand.'))
388 type = c
['SEARCH_TYPE']
389 if type not in ['mixed', 'recent', 'popular']:
391 max_record
= c
['SEARCH_MAX_RECORD']
392 count
= min(max_record
, 100)
394 rel
= t
.search
.tweets(
401 printNicely('Newest tweets:')
402 for i
in reversed(xrange(count
)):
403 draw(t
=rel
[i
], keyword
=query
)
406 printNicely(magenta('I\'m afraid there is no result'))
413 t
= Twitter(auth
=authen())
414 t
.statuses
.update(status
=g
['stuff'])
421 t
= Twitter(auth
=authen())
423 id = int(g
['stuff'].split()[0])
425 printNicely(red('Sorry I can\'t understand.'))
427 tid
= c
['tweet_dict'][id]
428 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
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 tweet
= t
.statuses
.show(id=tid
)
445 formater
= format_quote(tweet
)
449 prefix
= light_magenta('Compose your ', rl
=True) + \
450 light_green('#comment: ', rl
=True)
451 comment
= raw_input(prefix
)
453 quote
= comment
.join(formater
.split('#comment'))
454 t
.statuses
.update(status
=quote
)
456 printNicely(light_magenta('No text added.'))
463 t
= Twitter(auth
=authen())
466 id = int(g
['stuff'].split()[0])
468 printNicely(red('Sorry I can\'t understand.'))
470 tid
= c
['tweet_dict'][id]
471 # Get display num if exist
473 num
= int(g
['stuff'].split()[1])
475 num
= c
['RETWEETS_SHOW_NUM']
476 # Get result and display
477 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
479 printNicely(magenta('This tweet has no retweet.'))
481 for tweet
in reversed(rt_ary
):
490 t
= Twitter(auth
=authen())
492 id = int(g
['stuff'].split()[0])
494 printNicely(red('Sorry I can\'t understand.'))
496 tid
= c
['tweet_dict'][id]
497 tweet
= t
.statuses
.show(id=tid
)
498 limit
= c
['CONVERSATION_MAX']
500 thread_ref
.append(tweet
)
501 prev_tid
= tweet
['in_reply_to_status_id']
502 while prev_tid
and limit
:
504 tweet
= t
.statuses
.show(id=prev_tid
)
505 prev_tid
= tweet
['in_reply_to_status_id']
506 thread_ref
.append(tweet
)
508 for tweet
in reversed(thread_ref
):
517 t
= Twitter(auth
=authen())
519 id = int(g
['stuff'].split()[0])
521 printNicely(red('Sorry I can\'t understand.'))
523 tid
= c
['tweet_dict'][id]
524 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
525 status
= ' '.join(g
['stuff'].split()[1:])
526 status
= '@' + user
+ ' ' + 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 original_tweet
= t
.statuses
.show(id=tid
)
542 text
= original_tweet
['text']
543 nick_ary
= [original_tweet
['user']['screen_name']]
544 for user
in list(original_tweet
['entities']['user_mentions']):
545 if user
['screen_name'] not in nick_ary \
546 and user
['screen_name'] != g
['original_name']:
547 nick_ary
.append(user
['screen_name'])
548 status
= ' '.join(g
['stuff'].split()[1:])
549 status
= ' '.join(['@' + nick
for nick
in nick_ary
]) + ' ' + str2u(status
)
550 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
557 t
= Twitter(auth
=authen())
559 id = int(g
['stuff'].split()[0])
561 printNicely(red('Sorry I can\'t understand.'))
563 tid
= c
['tweet_dict'][id]
564 t
.favorites
.create(_id
=tid
, include_entities
=False)
565 printNicely(green('Favorited.'))
566 draw(t
.statuses
.show(id=tid
))
574 t
= Twitter(auth
=authen())
576 id = int(g
['stuff'].split()[0])
578 printNicely(red('Sorry I can\'t understand.'))
580 tid
= c
['tweet_dict'][id]
581 t
.favorites
.destroy(_id
=tid
)
582 printNicely(green('Okay it\'s unfavorited.'))
583 draw(t
.statuses
.show(id=tid
))
589 Copy url of a tweet to clipboard
591 t
= Twitter(auth
=authen())
593 id = int(g
['stuff'].split()[0])
594 tid
= c
['tweet_dict'][id]
596 printNicely(red('Tweet id is not valid.'))
598 tweet
= t
.statuses
.show(id=tid
)
599 url
= 'https://twitter.com/' + \
600 tweet
['user']['screen_name'] + '/status/' + str(tid
)
602 if platform
.system().lower() == 'darwin':
603 os
.system("echo '%s' | pbcopy" % url
)
604 printNicely(green('Copied tweet\'s url to clipboard.'))
606 printNicely('Direct link: ' + yellow(url
))
613 t
= Twitter(auth
=authen())
615 id = int(g
['stuff'].split()[0])
617 printNicely(red('Sorry I can\'t understand.'))
619 tid
= c
['tweet_dict'][id]
620 t
.statuses
.destroy(id=tid
)
621 printNicely(green('Okay it\'s gone.'))
628 t
= Twitter(auth
=authen())
630 target
= g
['stuff'].split()[0]
631 if target
!= 'image':
633 id = int(g
['stuff'].split()[1])
634 tid
= c
['tweet_dict'][id]
635 tweet
= t
.statuses
.show(id=tid
)
636 media
= tweet
['entities']['media']
638 res
= requests
.get(m
['media_url'])
639 img
= Image
.open(BytesIO(res
.content
))
643 printNicely(red('Sorry I can\'t show this image.'))
650 t
= Twitter(auth
=authen())
652 if not g
['stuff'].isdigit():
654 tid
= c
['tweet_dict'][int(g
['stuff'])]
655 tweet
= t
.statuses
.show(id=tid
)
656 urls
= tweet
['entities']['urls']
658 printNicely(light_magenta('No url here @.@!'))
662 expanded_url
= url
['expanded_url']
663 webbrowser
.open(expanded_url
)
666 printNicely(red('Sorry I can\'t open url in this tweet.'))
673 t
= Twitter(auth
=authen())
674 num
= c
['MESSAGES_DISPLAY']
675 if g
['stuff'].isdigit():
681 inbox
= inbox
+ t
.direct_messages(
684 include_entities
=False,
689 inbox
= inbox
+ t
.direct_messages(
692 include_entities
=False,
696 num
= c
['MESSAGES_DISPLAY']
697 if g
['stuff'].isdigit():
702 sent
= sent
+ t
.direct_messages
.sent(
705 include_entities
=False,
710 sent
= sent
+ t
.direct_messages
.sent(
713 include_entities
=False,
718 uniq_inbox
= list(set(
719 [(m
['sender_screen_name'], m
['sender']['name']) for m
in inbox
]
721 uniq_sent
= list(set(
722 [(m
['recipient_screen_name'], m
['recipient']['name']) for m
in sent
]
724 for partner
in uniq_inbox
:
725 inbox_ary
= [m
for m
in inbox
if m
['sender_screen_name'] == partner
[0]]
727 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
728 d
[partner
] = inbox_ary
+ sent_ary
729 for partner
in uniq_sent
:
732 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
733 g
['message_threads'] = print_threads(d
)
738 View a thread of message
741 thread_id
= int(g
['stuff'])
743 g
['message_threads'][thread_id
],
748 printNicely(red('No such thread.'))
753 Send a direct message
755 t
= Twitter(auth
=authen())
757 user
= g
['stuff'].split()[0]
758 if user
[0].startswith('@'):
759 content
= ' '.join(g
['stuff'].split()[1:])
760 t
.direct_messages
.new(
761 screen_name
=user
[1:],
764 printNicely(green('Message sent.'))
766 printNicely(red('A name should begin with a \'@\''))
769 printNicely(red('Sorry I can\'t understand.'))
776 t
= Twitter(auth
=authen())
778 id = int(g
['stuff'].split()[0])
780 printNicely(red('Sorry I can\'t understand.'))
781 mid
= c
['message_dict'][id]
782 t
.direct_messages
.destroy(id=mid
)
783 printNicely(green('Message deleted.'))
788 List friends for followers
790 t
= Twitter(auth
=authen())
793 name
= g
['stuff'].split()[1]
794 if name
.startswith('@'):
797 printNicely(red('A name should begin with a \'@\''))
798 raise Exception('Invalid name')
800 name
= g
['original_name']
801 # Get list followers or friends
803 target
= g
['stuff'].split()[0]
805 printNicely(red('Omg some syntax is wrong.'))
808 d
= {'fl': 'followers', 'fr': 'friends'}
812 while next_cursor
!= 0:
813 list = getattr(t
, d
[target
]).list(
817 include_entities
=False,
819 for u
in list['users']:
820 rel
[u
['name']] = '@' + u
['screen_name']
821 next_cursor
= list['next_cursor']
823 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
825 user
= ' ' + cycle_color(name
)
826 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
834 t
= Twitter(auth
=authen())
835 screen_name
= g
['stuff'].split()[0]
836 if screen_name
.startswith('@'):
837 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
838 printNicely(green('You are following ' + screen_name
+ ' now!'))
840 printNicely(red('A name should begin with a \'@\''))
847 t
= Twitter(auth
=authen())
848 screen_name
= g
['stuff'].split()[0]
849 if screen_name
.startswith('@'):
850 t
.friendships
.destroy(
851 screen_name
=screen_name
[1:],
852 include_entities
=False)
853 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
855 printNicely(red('A name should begin with a \'@\''))
862 t
= Twitter(auth
=authen())
864 screen_name
= g
['stuff'].split()[0]
866 printNicely(red('A name should be specified. '))
868 if screen_name
.startswith('@'):
870 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
871 if isinstance(rel
, dict):
872 printNicely(green(screen_name
+ ' is muted.'))
873 c
['IGNORE_LIST'] += screen_name
874 c
['IGNORE_LIST'] = list(set(c
['IGNORE_LIST']))
876 printNicely(red(rel
))
879 printNicely(red('Something is wrong, can not mute now :('))
881 printNicely(red('A name should begin with a \'@\''))
888 t
= Twitter(auth
=authen())
890 screen_name
= g
['stuff'].split()[0]
892 printNicely(red('A name should be specified. '))
894 if screen_name
.startswith('@'):
896 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
897 if isinstance(rel
, dict):
898 printNicely(green(screen_name
+ ' is unmuted.'))
899 c
['IGNORE_LIST'].remove(screen_name
)
901 printNicely(red(rel
))
903 printNicely(red('Maybe you are not muting this person ?'))
905 printNicely(red('A name should begin with a \'@\''))
912 # Get dict of muting users
913 md
= build_mute_dict(dict_data
=True)
914 printNicely('All: ' + str(len(md
)) + ' people.')
916 user
= ' ' + cycle_color(md
[name
])
917 user
+= color_func(c
['TWEET']['nick'])(' ' + name
+ ' ')
919 # Update from Twitter
920 c
['IGNORE_LIST'] = [n
for n
in md
]
927 t
= Twitter(auth
=authen())
928 screen_name
= g
['stuff'].split()[0]
929 if screen_name
.startswith('@'):
931 screen_name
=screen_name
[1:],
932 include_entities
=False,
934 printNicely(green('You blocked ' + screen_name
+ '.'))
936 printNicely(red('A name should begin with a \'@\''))
943 t
= Twitter(auth
=authen())
944 screen_name
= g
['stuff'].split()[0]
945 if screen_name
.startswith('@'):
947 screen_name
=screen_name
[1:],
948 include_entities
=False,
950 printNicely(green('Unblock ' + screen_name
+ ' success!'))
952 printNicely(red('A name should begin with a \'@\''))
957 Report a user as a spam account
959 t
= Twitter(auth
=authen())
960 screen_name
= g
['stuff'].split()[0]
961 if screen_name
.startswith('@'):
963 screen_name
=screen_name
[1:])
964 printNicely(green('You reported ' + screen_name
+ '.'))
966 printNicely(red('Sorry I can\'t understand.'))
974 list_name
= raw_input(
975 light_magenta('Give me the list\'s name ("@owner/list_name"): ', rl
=True))
976 # Get list name and owner
978 owner
, slug
= list_name
.split('/')
979 if slug
.startswith('@'):
984 light_magenta('List name should follow "@owner/list_name" format.'))
985 raise Exception('Wrong list name')
988 def check_slug(list_name
):
992 # Get list name and owner
994 owner
, slug
= list_name
.split('/')
995 if slug
.startswith('@'):
1000 light_magenta('List name should follow "@owner/list_name" format.'))
1001 raise Exception('Wrong list name')
1008 rel
= t
.lists
.list(screen_name
=g
['original_name'])
1012 printNicely(light_magenta('You belong to no lists :)'))
1019 owner
, slug
= get_slug()
1020 res
= t
.lists
.statuses(
1022 owner_screen_name
=owner
,
1023 count
=c
['LIST_MAX'],
1024 include_entities
=False)
1025 for tweet
in reversed(res
):
1030 def list_members(t
):
1034 owner
, slug
= get_slug()
1038 while next_cursor
!= 0:
1039 m
= t
.lists
.members(
1041 owner_screen_name
=owner
,
1043 include_entities
=False)
1044 for u
in m
['users']:
1045 rel
[u
['name']] = '@' + u
['screen_name']
1046 next_cursor
= m
['next_cursor']
1047 printNicely('All: ' + str(len(rel
)) + ' members.')
1049 user
= ' ' + cycle_color(name
)
1050 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1054 def list_subscribers(t
):
1058 owner
, slug
= get_slug()
1062 while next_cursor
!= 0:
1063 m
= t
.lists
.subscribers(
1065 owner_screen_name
=owner
,
1067 include_entities
=False)
1068 for u
in m
['users']:
1069 rel
[u
['name']] = '@' + u
['screen_name']
1070 next_cursor
= m
['next_cursor']
1071 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
1073 user
= ' ' + cycle_color(name
)
1074 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1080 Add specific user to a list
1082 owner
, slug
= get_slug()
1084 user_name
= raw_input(
1086 'Give me name of the newbie: ',
1088 if user_name
.startswith('@'):
1089 user_name
= user_name
[1:]
1091 t
.lists
.members
.create(
1093 owner_screen_name
=owner
,
1094 screen_name
=user_name
)
1095 printNicely(green('Added.'))
1098 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
1103 Remove specific user from a list
1105 owner
, slug
= get_slug()
1107 user_name
= raw_input(
1109 'Give me name of the unlucky one: ',
1111 if user_name
.startswith('@'):
1112 user_name
= user_name
[1:]
1114 t
.lists
.members
.destroy(
1116 owner_screen_name
=owner
,
1117 screen_name
=user_name
)
1118 printNicely(green('Gone.'))
1121 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
1124 def list_subscribe(t
):
1128 owner
, slug
= get_slug()
1131 t
.lists
.subscribers
.create(
1133 owner_screen_name
=owner
)
1134 printNicely(green('Done.'))
1138 light_magenta('I\'m sorry you can not subscribe to this list.'))
1141 def list_unsubscribe(t
):
1145 owner
, slug
= get_slug()
1148 t
.lists
.subscribers
.destroy(
1150 owner_screen_name
=owner
)
1151 printNicely(green('Done.'))
1155 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
1164 while next_cursor
!= 0:
1165 res
= t
.lists
.ownerships(
1166 screen_name
=g
['original_name'],
1169 next_cursor
= res
['next_cursor']
1173 printNicely(light_magenta('You own no lists :)'))
1180 name
= raw_input(light_magenta('New list\'s name: ', rl
=True))
1183 'New list\'s mode (public/private): ',
1185 description
= raw_input(
1187 'New list\'s description: ',
1193 description
=description
)
1194 printNicely(green(name
+ ' list is created.'))
1197 printNicely(red('Oops something is wrong with Twitter :('))
1206 'Your list that you want to update: ',
1210 'Update name (leave blank to unchange): ',
1212 mode
= raw_input(light_magenta('Update mode (public/private): ', rl
=True))
1213 description
= raw_input(light_magenta('Update description: ', rl
=True))
1217 slug
='-'.join(slug
.split()),
1218 owner_screen_name
=g
['original_name'],
1221 description
=description
)
1225 owner_screen_name
=g
['original_name'],
1227 description
=description
)
1228 printNicely(green(slug
+ ' list is updated.'))
1231 printNicely(red('Oops something is wrong with Twitter :('))
1240 'Your list that you want to delete: ',
1244 slug
='-'.join(slug
.split()),
1245 owner_screen_name
=g
['original_name'])
1246 printNicely(green(slug
+ ' list is deleted.'))
1249 printNicely(red('Oops something is wrong with Twitter :('))
1256 t
= Twitter(auth
=authen())
1257 # List all lists or base on action
1259 g
['list_action'] = g
['stuff'].split()[0]
1266 'all_mem': list_members
,
1267 'all_sub': list_subscribers
,
1270 'sub': list_subscribe
,
1271 'unsub': list_unsubscribe
,
1274 'update': list_update
,
1278 return action_ary
[g
['list_action']](t
)
1280 printNicely(red('Please try again.'))
1288 target
= g
['stuff'].split()[0]
1290 args
= parse_arguments()
1292 if g
['stuff'].split()[-1] == '-f':
1293 guide
= 'To ignore an option, just hit Enter key.'
1294 printNicely(light_magenta(guide
))
1295 only
= raw_input('Only nicks [Ex: @xxx,@yy]: ')
1296 ignore
= raw_input('Ignore nicks [Ex: @xxx,@yy]: ')
1297 args
.filter = filter(None, only
.split(','))
1298 args
.ignore
= filter(None, ignore
.split(','))
1300 printNicely(red('Sorry, wrong format.'))
1303 g
['stream_stop'] = True
1305 stuff
= g
['stuff'].split()[1]
1310 'public': spawn_public_stream
,
1311 'list': spawn_list_stream
,
1312 'mine': spawn_personal_stream
,
1314 spawn_dict
.get(target
)(args
, stuff
)
1317 printNicely(red('Sorry I can\'t understand.'))
1322 Unix's command `cal`
1325 rel
= os
.popen('cal').read().split('\n')
1328 show_calendar(month
, date
, rel
)
1333 List and change theme
1337 for theme
in g
['themes']:
1338 line
= light_magenta(theme
)
1339 if c
['THEME'] == theme
:
1340 line
= ' ' * 2 + light_yellow('* ') + line
1342 line
= ' ' * 4 + line
1348 c
['THEME'] = reload_theme(g
['stuff'], c
['THEME'])
1349 # Redefine decorated_name
1350 g
['decorated_name'] = lambda x
: color_func(
1351 c
['DECORATED_NAME'])(
1353 printNicely(green('Theme changed.'))
1355 printNicely(red('No such theme exists.'))
1360 Browse and change config
1362 all_config
= get_all_config()
1363 g
['stuff'] = g
['stuff'].strip()
1366 for k
in all_config
:
1368 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1370 guide
= 'Detailed explanation can be found at ' + \
1371 color_func(c
['TWEET']['link'])(
1372 'http://rainbowstream.readthedocs.org/en/latest/#config-explanation')
1374 # Print specific config
1375 elif len(g
['stuff'].split()) == 1:
1376 if g
['stuff'] in all_config
:
1379 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1382 printNicely(red('No such config key.'))
1383 # Print specific config's default value
1384 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'default':
1385 key
= g
['stuff'].split()[0]
1387 value
= get_default_config(key
)
1388 line
= ' ' * 2 + green(key
) + ': ' + light_magenta(value
)
1392 printNicely(red('Just can not get the default.'))
1393 # Delete specific config key in config file
1394 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'drop':
1395 key
= g
['stuff'].split()[0]
1398 printNicely(green('Config key is dropped.'))
1401 printNicely(red('Just can not drop the key.'))
1402 # Set specific config
1403 elif len(g
['stuff'].split()) == 3 and g
['stuff'].split()[1] == '=':
1404 key
= g
['stuff'].split()[0]
1405 value
= g
['stuff'].split()[-1]
1406 if key
== 'THEME' and not validate_theme(value
):
1407 printNicely(red('Invalid theme\'s value.'))
1410 set_config(key
, value
)
1411 # Keys that needs to be apply immediately
1413 c
['THEME'] = reload_theme(value
, c
['THEME'])
1414 g
['decorated_name'] = lambda x
: color_func(
1415 c
['DECORATED_NAME'])('[' + x
+ ']: ')
1416 elif key
== 'PREFIX':
1417 g
['PREFIX'] = u2str(emojize(format_prefix(
1418 listname
=g
['listname'],
1419 keyword
=g
['keyword']
1422 printNicely(green('Updated successfully.'))
1425 printNicely(red('Just can not set the key.'))
1427 printNicely(light_magenta('Sorry I can\'s understand.'))
1430 def help_discover():
1435 # Discover the world
1437 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1438 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1439 'You can try ' + light_green('trend US') + ' or ' + \
1440 light_green('trend JP Tokyo') + '.\n'
1441 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1442 light_green('home 7') + ' will show 7 tweets.\n'
1444 light_green('notification') + ' will show your recent notification.\n'
1445 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1446 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1447 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1448 magenta('@mdo') + '.\n'
1449 usage
+= s
* 2 + light_green('view @mdo') + \
1450 ' will show ' + magenta('@mdo') + '\'s home.\n'
1451 usage
+= s
* 2 + light_green('s AKB48') + ' will search for "' + \
1452 light_yellow('AKB48') + '" and return 5 newest tweet. ' + \
1453 'Search can be performed with or without hashtag.\n'
1464 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1465 usage
+= s
* 2 + light_green('t oops ') + \
1466 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1468 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1469 light_yellow('[id=12]') + '.\n'
1471 light_green('quote 12 ') + ' will quote the tweet with ' + \
1472 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1473 'the quote will be canceled.\n'
1475 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1476 light_yellow('[id=12]') + '.\n'
1477 usage
+= s
* 2 + light_green('conversation 12') + ' will show the chain of ' + \
1478 'replies prior to the tweet with ' + light_yellow('[id=12]') + '.\n'
1479 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1480 light_yellow('oops') + '" to the owner of the tweet with ' + \
1481 light_yellow('[id=12]') + '.\n'
1482 usage
+= s
* 2 + light_green('repall 12 oops') + ' will reply "' + \
1483 light_yellow('oops') + '" to all people in the tweet with ' + \
1484 light_yellow('[id=12]') + '.\n'
1486 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1487 light_yellow('[id=12]') + '.\n'
1489 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1490 light_yellow('[id=12]') + '.\n'
1492 light_green('share 12 ') + ' will get the direct link of the tweet with ' + \
1493 light_yellow('[id=12]') + '.\n'
1495 light_green('del 12 ') + ' will delete tweet with ' + \
1496 light_yellow('[id=12]') + '.\n'
1497 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1498 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1499 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1500 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1504 def help_messages():
1511 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1512 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1513 light_green('inbox 7') + ' will show newest 7 messages.\n'
1514 usage
+= s
* 2 + light_green('thread 2') + ' will show full thread with ' + \
1515 light_yellow('[thread_id=2]') + '.\n'
1516 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1517 magenta('@dtvd88') + '.\n'
1518 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1519 light_yellow('[message_id=5]') + '.\n'
1523 def help_friends_and_followers():
1525 Friends and Followers
1528 # Follower and following
1530 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1532 light_green('ls fl') + \
1533 ' will list all followers (people who are following you).\n'
1535 light_green('ls fr') + \
1536 ' will list all friends (people who you are following).\n'
1537 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1538 magenta('@dtvd88') + '.\n'
1539 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1540 magenta('@dtvd88') + '.\n'
1541 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1542 magenta('@dtvd88') + '.\n'
1543 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1544 magenta('@dtvd88') + '.\n'
1545 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1546 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1547 magenta('@dtvd88') + '.\n'
1548 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1549 magenta('@dtvd88') + '.\n'
1550 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1551 magenta('@dtvd88') + ' as a spam account.\n'
1562 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1563 usage
+= s
* 2 + light_green('list') + \
1564 ' will show all lists you are belong to.\n'
1565 usage
+= s
* 2 + light_green('list home') + \
1566 ' will show timeline of list. You will be asked for list\'s name.\n'
1567 usage
+= s
* 2 + light_green('list all_mem') + \
1568 ' will show list\'s all members.\n'
1569 usage
+= s
* 2 + light_green('list all_sub') + \
1570 ' will show list\'s all subscribers.\n'
1571 usage
+= s
* 2 + light_green('list add') + \
1572 ' will add specific person to a list owned by you.' + \
1573 ' You will be asked for list\'s name and person\'s name.\n'
1574 usage
+= s
* 2 + light_green('list rm') + \
1575 ' will remove specific person from a list owned by you.' + \
1576 ' You will be asked for list\'s name and person\'s name.\n'
1577 usage
+= s
* 2 + light_green('list sub') + \
1578 ' will subscribe you to a specific list.\n'
1579 usage
+= s
* 2 + light_green('list unsub') + \
1580 ' will unsubscribe you from a specific list.\n'
1581 usage
+= s
* 2 + light_green('list own') + \
1582 ' will show all list owned by you.\n'
1583 usage
+= s
* 2 + light_green('list new') + \
1584 ' will create a new list.\n'
1585 usage
+= s
* 2 + light_green('list update') + \
1586 ' will update a list owned by you.\n'
1587 usage
+= s
* 2 + light_green('list del') + \
1588 ' will delete a list owned by you.\n'
1599 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1600 usage
+= s
* 2 + light_green('switch public #AKB') + \
1601 ' will switch to public stream and follow "' + \
1602 light_yellow('AKB') + '" keyword.\n'
1603 usage
+= s
* 2 + light_green('switch mine') + \
1604 ' will switch to your personal stream.\n'
1605 usage
+= s
* 2 + light_green('switch mine -f ') + \
1606 ' will prompt to enter the filter.\n'
1607 usage
+= s
* 3 + light_yellow('Only nicks') + \
1608 ' filter will decide nicks will be INCLUDE ONLY.\n'
1609 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1610 ' filter will decide nicks will be EXCLUDE.\n'
1611 usage
+= s
* 2 + light_green('switch list') + \
1612 ' will switch to a Twitter list\'s stream. You will be asked for list name\n'
1621 h
, w
= os
.popen('stty size', 'r').read().split()
1624 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1625 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1626 usage
+= s
+ 'You are ' + \
1627 light_yellow('already') + ' on your personal stream.\n'
1628 usage
+= s
+ 'Any update from Twitter will show up ' + \
1629 light_yellow('immediately') + '.\n'
1630 usage
+= s
+ 'In addition, following commands are available right now:\n'
1631 # Twitter help section
1633 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1634 usage
+= s
* 2 + light_green('h discover') + \
1635 ' will show help for discover commands.\n'
1636 usage
+= s
* 2 + light_green('h tweets') + \
1637 ' will show help for tweets commands.\n'
1638 usage
+= s
* 2 + light_green('h messages') + \
1639 ' will show help for messages commands.\n'
1640 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1641 ' will show help for friends and followers commands.\n'
1642 usage
+= s
* 2 + light_green('h list') + \
1643 ' will show help for list commands.\n'
1644 usage
+= s
* 2 + light_green('h stream') + \
1645 ' will show help for stream commands.\n'
1648 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1649 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1650 'will be evaluate by Python interpreter.\n'
1651 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1652 ' for current month.\n'
1655 usage
+= s
+ grey(u
'\u266A' + ' Config \n')
1656 usage
+= s
* 2 + light_green('theme') + ' will list available theme. ' + \
1657 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1658 ' theme immediately.\n'
1659 usage
+= s
* 2 + light_green('config') + ' will list all config.\n'
1661 light_green('config ASCII_ART') + ' will output current value of ' +\
1662 light_yellow('ASCII_ART') + ' config key.\n'
1664 light_green('config TREND_MAX default') + ' will output default value of ' + \
1665 light_yellow('TREND_MAX') + ' config key.\n'
1667 light_green('config CUSTOM_CONFIG drop') + ' will drop ' + \
1668 light_yellow('CUSTOM_CONFIG') + ' config key.\n'
1670 light_green('config IMAGE_ON_TERM = true') + ' will set value of ' + \
1671 light_yellow('IMAGE_ON_TERM') + ' config key to ' + \
1672 light_yellow('True') + '.\n'
1675 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1676 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1677 usage
+= s
* 2 + light_green('p') + ' will pause the stream.\n'
1678 usage
+= s
* 2 + light_green('r') + ' will unpause the stream.\n'
1679 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1680 usage
+= s
* 2 + light_green('v') + ' will show version info.\n'
1681 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1684 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1685 usage
+= s
+ 'Have fun and hang tight! \n'
1688 'discover': help_discover
,
1689 'tweets': help_tweets
,
1690 'messages': help_messages
,
1691 'friends_and_followers': help_friends_and_followers
,
1693 'stream': help_stream
,
1698 lambda: printNicely(red('No such command.'))
1706 Pause stream display
1709 printNicely(green('Stream is paused'))
1717 printNicely(green('Stream is running back now'))
1733 printNicely(green('See you next time :)'))
1741 Reset prefix of line
1744 if c
.get('USER_JSON_ERROR'):
1745 printNicely(red('Your ~/.rainbow_config.json is messed up:'))
1746 printNicely(red('>>> ' + c
['USER_JSON_ERROR']))
1748 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1751 printNicely(str(eval(g
['cmd'])))
1804 # Handle function set
1857 return dict(zip(cmdset
, funcset
)).get(cmd
, reset
)
1862 Listen to user's input
1867 ['public', 'mine', 'list'], # switch
1886 ['image'], # show image
1888 ['fl', 'fr'], # list
1890 [i
for i
in g
['message_threads']], # sent
1915 [key
for key
in dict(get_all_config())], # config
1916 g
['themes'], # theme
1921 'friends_and_followers',
1932 init_interactive_shell(d
)
1939 # Only use PREFIX as a string with raw_input
1940 line
= raw_input(g
['decorated_name'](g
['PREFIX']))
1943 # Save cmd to compare with readline buffer
1944 g
['cmd'] = line
.strip()
1945 # Get short cmd to pass to handle function
1947 cmd
= line
.split()[0]
1950 # Lock the semaphore
1952 # Save cmd to global variable and call process
1953 g
['stuff'] = ' '.join(line
.split()[1:])
1954 # Check tweet length
1955 # Process the command
1958 if cmd
in ['switch', 't', 'rt', 'rep']:
1962 # Release the semaphore lock
1966 except TwitterHTTPError
as e
:
1967 detail_twitter_error(e
)
1970 printNicely(red('OMG something is wrong with Twitter API right now.'))
1973 def reconn_notice():
1975 Notice when Hangup or Timeout
1977 guide
= light_magenta('You can use ') + \
1978 light_green('switch') + \
1979 light_magenta(' command to return to your stream.\n')
1980 guide
+= light_magenta('Type ') + \
1981 light_green('h stream') + \
1982 light_magenta(' for more details.')
1984 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
1988 def stream(domain
, args
, name
='Rainbow Stream'):
1994 c
['USER_DOMAIN']: name
,
1995 c
['PUBLIC_DOMAIN']: args
.track_keywords
or 'Global',
1996 c
['SITE_DOMAIN']: name
,
1999 ascii_art(art_dict
.get(domain
, name
))
2000 # These arguments are optional:
2002 timeout
=0.5, # To check g['stream_stop'] after each 0.5 s
2004 heartbeat_timeout
=c
['HEARTBEAT_TIMEOUT'] * 60)
2007 if args
.track_keywords
:
2008 query_args
['track'] = args
.track_keywords
2010 stream
= TwitterStream(
2015 if domain
== c
['USER_DOMAIN']:
2016 tweet_iter
= stream
.user(**query_args
)
2017 elif domain
== c
['SITE_DOMAIN']:
2018 tweet_iter
= stream
.site(**query_args
)
2020 if args
.track_keywords
:
2021 tweet_iter
= stream
.statuses
.filter(**query_args
)
2023 tweet_iter
= stream
.statuses
.sample()
2024 # Block new stream until other one exits
2025 StreamLock
.acquire()
2026 g
['stream_stop'] = False
2027 last_tweet_time
= time
.time()
2028 for tweet
in tweet_iter
:
2030 printNicely('-- None --')
2031 elif tweet
is Timeout
:
2032 # Because the stream check for each 0.3s
2033 # so we shouldn't output anything here
2034 if(g
['stream_stop']):
2035 StreamLock
.release()
2037 elif tweet
is HeartbeatTimeout
:
2038 printNicely('-- Heartbeat Timeout --')
2040 StreamLock
.release()
2042 elif tweet
is Hangup
:
2043 printNicely('-- Hangup --')
2045 StreamLock
.release()
2047 elif tweet
.get('text'):
2048 # Slow down the stream by STREAM_DELAY config key
2049 if time
.time() - last_tweet_time
< c
['STREAM_DELAY']:
2051 last_tweet_time
= time
.time()
2052 # Check the semaphore pause and lock (stream process only)
2060 keyword
=args
.track_keywords
,
2065 # Current readline buffer
2066 current_buffer
= readline
.get_line_buffer().strip()
2067 # There is an unexpected behaviour in MacOSX readline + Python 2:
2068 # after completely delete a word after typing it,
2069 # somehow readline buffer still contains
2070 # the 1st character of that word
2071 if current_buffer
and g
['cmd'] != current_buffer
:
2073 g
['decorated_name'](g
['PREFIX']) + current_buffer
)
2075 elif not c
['HIDE_PROMPT']:
2076 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2078 elif tweet
.get('direct_message'):
2079 # Check the semaphore pause and lock (stream process only)
2084 print_message(tweet
['direct_message'])
2085 elif tweet
.get('event'):
2086 c
['events'].append(tweet
)
2088 except TwitterHTTPError
as e
:
2091 magenta('We have connection problem with twitter stream API right now :('))
2092 detail_twitter_error(e
)
2093 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2097 magenta('There seems to be a connection problem.'))
2102 def spawn_public_stream(args
, keyword
=None):
2104 Spawn a new public stream
2106 # Only set keyword if specified
2108 if keyword
[0] == '#':
2109 keyword
= keyword
[1:]
2110 args
.track_keywords
= keyword
2111 g
['keyword'] = keyword
2113 g
['keyword'] = 'Global'
2114 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
2117 th
= threading
.Thread(
2126 def spawn_list_stream(args
, stuff
=None):
2128 Spawn a new list stream
2131 owner
, slug
= check_slug(stuff
)
2133 owner
, slug
= get_slug()
2135 # Force python 2 not redraw readline buffer
2136 listname
= '/'.join([owner
, slug
])
2137 # Set the listname variable
2138 # and reset tracked keyword
2139 g
['listname'] = listname
2141 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
2142 listname
=g
['listname']
2144 printNicely(light_yellow('getting list members ...'))
2146 t
= Twitter(auth
=authen())
2149 while next_cursor
!= 0:
2150 m
= t
.lists
.members(
2152 owner_screen_name
=owner
,
2154 include_entities
=False)
2155 for u
in m
['users']:
2156 members
.append('@' + u
['screen_name'])
2157 next_cursor
= m
['next_cursor']
2158 printNicely(light_yellow('... done.'))
2159 # Build thread filter array
2160 args
.filter = members
2162 th
= threading
.Thread(
2172 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
2174 printNicely(red('Ignore: ' + str(len(args
.ignore
)) + ' people.'))
2178 def spawn_personal_stream(args
, stuff
=None):
2180 Spawn a new personal stream
2182 # Reset the tracked keyword and listname
2183 g
['keyword'] = g
['listname'] = ''
2185 g
['PREFIX'] = u2str(emojize(format_prefix()))
2187 th
= threading
.Thread(
2192 g
['original_name']))
2202 args
= parse_arguments()
2206 # Twitter API connection problem
2207 except TwitterHTTPError
as e
:
2210 magenta('We have connection problem with twitter REST API right now :('))
2211 detail_twitter_error(e
)
2214 # Proxy connection problem
2215 except (socks
.ProxyConnectionError
, URLError
):
2217 magenta('There seems to be a connection problem.'))
2219 magenta('You might want to check your proxy settings (host, port and type)!'))
2223 # Spawn stream thread
2224 target
= args
.stream
.split()[0]
2225 if target
== 'mine':
2226 spawn_personal_stream(args
)
2229 stuff
= args
.stream
.split()[1]
2233 'public': spawn_public_stream
,
2234 'list': spawn_list_stream
,
2236 spawn_dict
.get(target
)(args
, stuff
)
2238 # Start listen process