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.')
77 '--higher-resolution',
79 help='Display images in high(er) resolution.')
83 help='Use HTTP/SOCKS proxy for network connections.')
88 help='HTTP/SOCKS proxy port (Default: 8080).')
93 help='Proxy type (HTTP, SOCKS4, SOCKS5; Default: SOCKS5).')
94 return parser
.parse_args()
97 def proxy_connect(args
):
99 Connect to specified proxy
102 # Setup proxy by monkeypatching the standard lib
103 if args
.proxy_type
.lower() == "socks5" or not args
.proxy_type
:
104 socks
.set_default_proxy(
105 socks
.SOCKS5
, args
.proxy_host
,
106 int(args
.proxy_port
))
107 elif args
.proxy_type
.lower() == "http":
108 socks
.set_default_proxy(
109 socks
.HTTP
, args
.proxy_host
,
110 int(args
.proxy_port
))
111 elif args
.proxy_type
.lower() == "socks4":
112 socks
.set_default_proxy(
113 socks
.SOCKS4
, args
.proxy_host
,
114 int(args
.proxy_port
))
117 magenta('Sorry, wrong proxy type specified! Aborting...'))
119 socket
.socket
= socks
.socksocket
124 Authenticate with Twitter OAuth
126 # When using rainbow stream you must authorize.
127 twitter_credential
= os
.environ
.get(
131 '')) + os
.sep
+ '.rainbow_oauth'
132 if not os
.path
.exists(twitter_credential
):
133 oauth_dance('Rainbow Stream',
137 oauth_token
, oauth_token_secret
= read_token_file(twitter_credential
)
145 def build_mute_dict(dict_data
=False):
149 t
= Twitter(auth
=authen())
152 screen_name_list
= []
155 while next_cursor
!= 0:
156 list = t
.mutes
.users
.list(
157 screen_name
=g
['original_name'],
160 include_entities
=False,
162 screen_name_list
+= ['@' + u
['screen_name'] for u
in list['users']]
163 name_list
+= [u
['name'] for u
in list['users']]
164 next_cursor
= list['next_cursor']
165 # Return dict or list
167 return dict(zip(screen_name_list
, name_list
))
169 return screen_name_list
174 Save traceback when run in debug mode
177 g
['traceback'].append(traceback
.format_exc())
180 def upgrade_center():
182 Check latest and notify to upgrade
185 current
= pkg_resources
.get_distribution('rainbowstream').version
186 url
= 'https://raw.githubusercontent.com/DTVD/rainbowstream/master/setup.py'
187 readme
= requests
.get(url
).text
188 latest
= readme
.split('version = \'')[1].split('\'')[0]
189 if current
!= latest
:
190 notice
= light_magenta('RainbowStream latest version is ')
191 notice
+= light_green(latest
)
192 notice
+= light_magenta(' while your current version is ')
193 notice
+= light_yellow(current
) + '\n'
194 notice
+= light_magenta('You should upgrade with ')
195 notice
+= light_green('pip install -U rainbowstream')
198 notice
= light_yellow('You are running latest version (')
199 notice
+= light_green(current
)
200 notice
+= light_yellow(')')
211 ctrl_c_handler
= lambda signum
, frame
: quit()
212 signal
.signal(signal
.SIGINT
, ctrl_c_handler
)
216 t
= Twitter(auth
=authen())
217 credential
= t
.account
.verify_credentials()
218 screen_name
= '@' + credential
['screen_name']
219 name
= credential
['name']
220 c
['original_name'] = g
['original_name'] = screen_name
[1:]
221 g
['listname'] = g
['keyword'] = ''
222 g
['PREFIX'] = u2str(emojize(format_prefix()))
223 g
['full_name'] = name
224 g
['decorated_name'] = lambda x
: color_func(
225 c
['DECORATED_NAME'])('[' + x
+ ']: ', rl
=True)
227 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
228 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
231 g
['message_threads'] = {}
234 # Debug option default = True
241 # Init tweet dict and message dict
243 c
['message_dict'] = []
245 c
['IMAGE_ON_TERM'] = args
.image_on_term
246 set_config('IMAGE_ON_TERM', str(c
['IMAGE_ON_TERM']))
248 c
['24BIT'] = args
.color_24bit
249 # Print images using half height blocks
250 c
['HIGHER_RESOLUTION'] = args
.higher_resolution
251 set_config('HIGHER_RESOLUTION', str(c
['HIGHER_RESOLUTION']))
252 # Check type of ONLY_LIST and IGNORE_LIST
253 if not isinstance(c
['ONLY_LIST'], list):
254 printNicely(red('ONLY_LIST is not a valid list value.'))
256 if not isinstance(c
['IGNORE_LIST'], list):
257 printNicely(red('IGNORE_LIST is not a valid list value.'))
258 c
['IGNORE_LIST'] = []
260 c
['IGNORE_LIST'] += build_mute_dict()
267 t
= Twitter(auth
=authen())
268 # Get country and town
270 country
= g
['stuff'].split()[0]
274 town
= g
['stuff'].split()[1]
277 avail
= t
.trends
.available()
280 trends
= t
.trends
.place(_id
=1)[0]['trends']
283 for location
in avail
:
284 # Search for country and Town
286 if location
['countryCode'] == country \
287 and location
['placeType']['name'] == 'Town' \
288 and location
['name'] == town
:
289 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
291 # Search for country only
293 if location
['countryCode'] == country \
294 and location
['placeType']['name'] == 'Country':
295 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
303 t
= Twitter(auth
=authen())
304 num
= c
['HOME_TWEET_NUM']
305 if g
['stuff'].isdigit():
306 num
= int(g
['stuff'])
307 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
317 for e
in c
['events']:
321 printNicely(magenta('Nothing at this time.'))
328 t
= Twitter(auth
=authen())
329 num
= c
['HOME_TWEET_NUM']
330 if g
['stuff'].isdigit():
331 num
= int(g
['stuff'])
332 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
339 Show profile of a specific user
341 t
= Twitter(auth
=authen())
343 screen_name
= g
['stuff'].split()[0]
345 printNicely(red('Sorry I can\'t understand.'))
347 if screen_name
.startswith('@'):
350 screen_name
=screen_name
[1:],
351 include_entities
=False)
355 printNicely(red('No user.'))
357 printNicely(red('A name should begin with a \'@\''))
364 t
= Twitter(auth
=authen())
366 user
= g
['stuff'].split()[0]
368 printNicely(red('Sorry I can\'t understand.'))
372 num
= int(g
['stuff'].split()[1])
374 num
= c
['HOME_TWEET_NUM']
375 for tweet
in reversed(
376 t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
380 printNicely(red('A name should begin with a \'@\''))
387 t
= Twitter(auth
=authen())
389 query
= g
['stuff'].strip()
391 printNicely(red('Sorry I can\'t understand.'))
393 type = c
['SEARCH_TYPE']
394 if type not in ['mixed', 'recent', 'popular']:
396 max_record
= c
['SEARCH_MAX_RECORD']
397 count
= min(max_record
, 100)
399 rel
= t
.search
.tweets(
406 printNicely('Newest tweets:')
407 for i
in reversed(xrange(count
)):
408 draw(t
=rel
[i
], keyword
=query
)
411 printNicely(magenta('I\'m afraid there is no result'))
418 t
= Twitter(auth
=authen())
419 t
.statuses
.update(status
=g
['stuff'])
426 t
= Twitter(auth
=authen())
428 id = int(g
['stuff'].split()[0])
430 printNicely(red('Sorry I can\'t understand.'))
432 tid
= c
['tweet_dict'][id]
433 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
441 t
= Twitter(auth
=authen())
443 id = int(g
['stuff'].split()[0])
445 printNicely(red('Sorry I can\'t understand.'))
447 tid
= c
['tweet_dict'][id]
448 tweet
= t
.statuses
.show(id=tid
)
450 formater
= format_quote(tweet
)
454 prefix
= light_magenta('Compose your ', rl
=True) + \
455 light_green('#comment: ', rl
=True)
456 comment
= raw_input(prefix
)
458 quote
= comment
.join(formater
.split('#comment'))
459 t
.statuses
.update(status
=quote
)
461 printNicely(light_magenta('No text added.'))
468 t
= Twitter(auth
=authen())
471 id = int(g
['stuff'].split()[0])
473 printNicely(red('Sorry I can\'t understand.'))
475 tid
= c
['tweet_dict'][id]
476 # Get display num if exist
478 num
= int(g
['stuff'].split()[1])
480 num
= c
['RETWEETS_SHOW_NUM']
481 # Get result and display
482 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
484 printNicely(magenta('This tweet has no retweet.'))
486 for tweet
in reversed(rt_ary
):
495 t
= Twitter(auth
=authen())
497 id = int(g
['stuff'].split()[0])
499 printNicely(red('Sorry I can\'t understand.'))
501 tid
= c
['tweet_dict'][id]
502 tweet
= t
.statuses
.show(id=tid
)
503 limit
= c
['CONVERSATION_MAX']
505 thread_ref
.append(tweet
)
506 prev_tid
= tweet
['in_reply_to_status_id']
507 while prev_tid
and limit
:
509 tweet
= t
.statuses
.show(id=prev_tid
)
510 prev_tid
= tweet
['in_reply_to_status_id']
511 thread_ref
.append(tweet
)
513 for tweet
in reversed(thread_ref
):
522 t
= Twitter(auth
=authen())
524 id = int(g
['stuff'].split()[0])
526 printNicely(red('Sorry I can\'t understand.'))
528 tid
= c
['tweet_dict'][id]
529 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
530 status
= ' '.join(g
['stuff'].split()[1:])
531 status
= '@' + user
+ ' ' + str2u(status
)
532 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
539 t
= Twitter(auth
=authen())
541 id = int(g
['stuff'].split()[0])
543 printNicely(red('Sorry I can\'t understand.'))
545 tid
= c
['tweet_dict'][id]
546 original_tweet
= t
.statuses
.show(id=tid
)
547 text
= original_tweet
['text']
548 nick_ary
= [original_tweet
['user']['screen_name']]
549 for user
in list(original_tweet
['entities']['user_mentions']):
550 if user
['screen_name'] not in nick_ary \
551 and user
['screen_name'] != g
['original_name']:
552 nick_ary
.append(user
['screen_name'])
553 status
= ' '.join(g
['stuff'].split()[1:])
554 status
= ' '.join(['@' + nick
for nick
in nick_ary
]) + ' ' + str2u(status
)
555 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
562 t
= Twitter(auth
=authen())
564 id = int(g
['stuff'].split()[0])
566 printNicely(red('Sorry I can\'t understand.'))
568 tid
= c
['tweet_dict'][id]
569 t
.favorites
.create(_id
=tid
, include_entities
=False)
570 printNicely(green('Favorited.'))
571 draw(t
.statuses
.show(id=tid
))
579 t
= Twitter(auth
=authen())
581 id = int(g
['stuff'].split()[0])
583 printNicely(red('Sorry I can\'t understand.'))
585 tid
= c
['tweet_dict'][id]
586 t
.favorites
.destroy(_id
=tid
)
587 printNicely(green('Okay it\'s unfavorited.'))
588 draw(t
.statuses
.show(id=tid
))
594 Copy url of a tweet to clipboard
596 t
= Twitter(auth
=authen())
598 id = int(g
['stuff'].split()[0])
599 tid
= c
['tweet_dict'][id]
601 printNicely(red('Tweet id is not valid.'))
603 tweet
= t
.statuses
.show(id=tid
)
604 url
= 'https://twitter.com/' + \
605 tweet
['user']['screen_name'] + '/status/' + str(tid
)
607 if platform
.system().lower() == 'darwin':
608 os
.system("echo '%s' | pbcopy" % url
)
609 printNicely(green('Copied tweet\'s url to clipboard.'))
611 printNicely('Direct link: ' + yellow(url
))
618 t
= Twitter(auth
=authen())
620 id = int(g
['stuff'].split()[0])
622 printNicely(red('Sorry I can\'t understand.'))
624 tid
= c
['tweet_dict'][id]
625 t
.statuses
.destroy(id=tid
)
626 printNicely(green('Okay it\'s gone.'))
633 t
= Twitter(auth
=authen())
635 target
= g
['stuff'].split()[0]
636 if target
!= 'image':
638 id = int(g
['stuff'].split()[1])
639 tid
= c
['tweet_dict'][id]
640 tweet
= t
.statuses
.show(id=tid
)
641 media
= tweet
['entities']['media']
643 res
= requests
.get(m
['media_url'])
644 img
= Image
.open(BytesIO(res
.content
))
648 printNicely(red('Sorry I can\'t show this image.'))
655 t
= Twitter(auth
=authen())
657 if not g
['stuff'].isdigit():
659 tid
= c
['tweet_dict'][int(g
['stuff'])]
660 tweet
= t
.statuses
.show(id=tid
)
661 link_prefix
= ('http://', 'https://')
662 link_ary
= [u
for u
in tweet
['text'].split()
663 if u
.startswith(link_prefix
)]
665 printNicely(light_magenta('No url here @.@!'))
667 for link
in link_ary
:
668 webbrowser
.open(link
)
671 printNicely(red('Sorry I can\'t open url in this tweet.'))
678 t
= Twitter(auth
=authen())
679 num
= c
['MESSAGES_DISPLAY']
680 if g
['stuff'].isdigit():
686 inbox
= inbox
+ t
.direct_messages(
689 include_entities
=False,
694 inbox
= inbox
+ t
.direct_messages(
697 include_entities
=False,
701 num
= c
['MESSAGES_DISPLAY']
702 if g
['stuff'].isdigit():
707 sent
= sent
+ t
.direct_messages
.sent(
710 include_entities
=False,
715 sent
= sent
+ t
.direct_messages
.sent(
718 include_entities
=False,
723 uniq_inbox
= list(set(
724 [(m
['sender_screen_name'], m
['sender']['name']) for m
in inbox
]
726 uniq_sent
= list(set(
727 [(m
['recipient_screen_name'], m
['recipient']['name']) for m
in sent
]
729 for partner
in uniq_inbox
:
730 inbox_ary
= [m
for m
in inbox
if m
['sender_screen_name'] == partner
[0]]
732 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
733 d
[partner
] = inbox_ary
+ sent_ary
734 for partner
in uniq_sent
:
737 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
738 g
['message_threads'] = print_threads(d
)
743 View a thread of message
746 thread_id
= int(g
['stuff'])
748 g
['message_threads'][thread_id
],
753 printNicely(red('No such thread.'))
758 Send a direct message
760 t
= Twitter(auth
=authen())
762 user
= g
['stuff'].split()[0]
763 if user
[0].startswith('@'):
764 content
= ' '.join(g
['stuff'].split()[1:])
765 t
.direct_messages
.new(
766 screen_name
=user
[1:],
769 printNicely(green('Message sent.'))
771 printNicely(red('A name should begin with a \'@\''))
774 printNicely(red('Sorry I can\'t understand.'))
781 t
= Twitter(auth
=authen())
783 id = int(g
['stuff'].split()[0])
785 printNicely(red('Sorry I can\'t understand.'))
786 mid
= c
['message_dict'][id]
787 t
.direct_messages
.destroy(id=mid
)
788 printNicely(green('Message deleted.'))
793 List friends for followers
795 t
= Twitter(auth
=authen())
798 name
= g
['stuff'].split()[1]
799 if name
.startswith('@'):
802 printNicely(red('A name should begin with a \'@\''))
803 raise Exception('Invalid name')
805 name
= g
['original_name']
806 # Get list followers or friends
808 target
= g
['stuff'].split()[0]
810 printNicely(red('Omg some syntax is wrong.'))
813 d
= {'fl': 'followers', 'fr': 'friends'}
817 while next_cursor
!= 0:
818 list = getattr(t
, d
[target
]).list(
822 include_entities
=False,
824 for u
in list['users']:
825 rel
[u
['name']] = '@' + u
['screen_name']
826 next_cursor
= list['next_cursor']
828 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
830 user
= ' ' + cycle_color(name
)
831 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
839 t
= Twitter(auth
=authen())
840 screen_name
= g
['stuff'].split()[0]
841 if screen_name
.startswith('@'):
842 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
843 printNicely(green('You are following ' + screen_name
+ ' now!'))
845 printNicely(red('A name should begin with a \'@\''))
852 t
= Twitter(auth
=authen())
853 screen_name
= g
['stuff'].split()[0]
854 if screen_name
.startswith('@'):
855 t
.friendships
.destroy(
856 screen_name
=screen_name
[1:],
857 include_entities
=False)
858 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
860 printNicely(red('A name should begin with a \'@\''))
867 t
= Twitter(auth
=authen())
869 screen_name
= g
['stuff'].split()[0]
871 printNicely(red('A name should be specified. '))
873 if screen_name
.startswith('@'):
875 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
876 if isinstance(rel
, dict):
877 printNicely(green(screen_name
+ ' is muted.'))
878 c
['IGNORE_LIST'] += [unc(screen_name
)]
879 c
['IGNORE_LIST'] = list(set(c
['IGNORE_LIST']))
881 printNicely(red(rel
))
884 printNicely(red('Something is wrong, can not mute now :('))
886 printNicely(red('A name should begin with a \'@\''))
893 t
= Twitter(auth
=authen())
895 screen_name
= g
['stuff'].split()[0]
897 printNicely(red('A name should be specified. '))
899 if screen_name
.startswith('@'):
901 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
902 if isinstance(rel
, dict):
903 printNicely(green(screen_name
+ ' is unmuted.'))
904 c
['IGNORE_LIST'].remove(screen_name
)
906 printNicely(red(rel
))
908 printNicely(red('Maybe you are not muting this person ?'))
910 printNicely(red('A name should begin with a \'@\''))
917 # Get dict of muting users
918 md
= build_mute_dict(dict_data
=True)
919 printNicely('All: ' + str(len(md
)) + ' people.')
921 user
= ' ' + cycle_color(md
[name
])
922 user
+= color_func(c
['TWEET']['nick'])(' ' + name
+ ' ')
924 # Update from Twitter
925 c
['IGNORE_LIST'] = [n
for n
in md
]
932 t
= Twitter(auth
=authen())
933 screen_name
= g
['stuff'].split()[0]
934 if screen_name
.startswith('@'):
936 screen_name
=screen_name
[1:],
937 include_entities
=False,
939 printNicely(green('You blocked ' + screen_name
+ '.'))
941 printNicely(red('A name should begin with a \'@\''))
948 t
= Twitter(auth
=authen())
949 screen_name
= g
['stuff'].split()[0]
950 if screen_name
.startswith('@'):
952 screen_name
=screen_name
[1:],
953 include_entities
=False,
955 printNicely(green('Unblock ' + screen_name
+ ' success!'))
957 printNicely(red('A name should begin with a \'@\''))
962 Report a user as a spam account
964 t
= Twitter(auth
=authen())
965 screen_name
= g
['stuff'].split()[0]
966 if screen_name
.startswith('@'):
968 screen_name
=screen_name
[1:])
969 printNicely(green('You reported ' + screen_name
+ '.'))
971 printNicely(red('Sorry I can\'t understand.'))
979 list_name
= raw_input(
980 light_magenta('Give me the list\'s name ("@owner/list_name"): ', rl
=True))
981 # Get list name and owner
983 owner
, slug
= list_name
.split('/')
984 if slug
.startswith('@'):
989 light_magenta('List name should follow "@owner/list_name" format.'))
990 raise Exception('Wrong list name')
993 def check_slug(list_name
):
997 # Get list name and owner
999 owner
, slug
= list_name
.split('/')
1000 if slug
.startswith('@'):
1005 light_magenta('List name should follow "@owner/list_name" format.'))
1006 raise Exception('Wrong list name')
1013 rel
= t
.lists
.list(screen_name
=g
['original_name'])
1017 printNicely(light_magenta('You belong to no lists :)'))
1024 owner
, slug
= get_slug()
1025 res
= t
.lists
.statuses(
1027 owner_screen_name
=owner
,
1028 count
=c
['LIST_MAX'],
1029 include_entities
=False)
1030 for tweet
in reversed(res
):
1035 def list_members(t
):
1039 owner
, slug
= get_slug()
1043 while next_cursor
!= 0:
1044 m
= t
.lists
.members(
1046 owner_screen_name
=owner
,
1048 include_entities
=False)
1049 for u
in m
['users']:
1050 rel
[u
['name']] = '@' + u
['screen_name']
1051 next_cursor
= m
['next_cursor']
1052 printNicely('All: ' + str(len(rel
)) + ' members.')
1054 user
= ' ' + cycle_color(name
)
1055 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1059 def list_subscribers(t
):
1063 owner
, slug
= get_slug()
1067 while next_cursor
!= 0:
1068 m
= t
.lists
.subscribers(
1070 owner_screen_name
=owner
,
1072 include_entities
=False)
1073 for u
in m
['users']:
1074 rel
[u
['name']] = '@' + u
['screen_name']
1075 next_cursor
= m
['next_cursor']
1076 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
1078 user
= ' ' + cycle_color(name
)
1079 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1085 Add specific user to a list
1087 owner
, slug
= get_slug()
1089 user_name
= raw_input(
1091 'Give me name of the newbie: ',
1093 if user_name
.startswith('@'):
1094 user_name
= user_name
[1:]
1096 t
.lists
.members
.create(
1098 owner_screen_name
=owner
,
1099 screen_name
=user_name
)
1100 printNicely(green('Added.'))
1103 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
1108 Remove specific user from a list
1110 owner
, slug
= get_slug()
1112 user_name
= raw_input(
1114 'Give me name of the unlucky one: ',
1116 if user_name
.startswith('@'):
1117 user_name
= user_name
[1:]
1119 t
.lists
.members
.destroy(
1121 owner_screen_name
=owner
,
1122 screen_name
=user_name
)
1123 printNicely(green('Gone.'))
1126 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
1129 def list_subscribe(t
):
1133 owner
, slug
= get_slug()
1136 t
.lists
.subscribers
.create(
1138 owner_screen_name
=owner
)
1139 printNicely(green('Done.'))
1143 light_magenta('I\'m sorry you can not subscribe to this list.'))
1146 def list_unsubscribe(t
):
1150 owner
, slug
= get_slug()
1153 t
.lists
.subscribers
.destroy(
1155 owner_screen_name
=owner
)
1156 printNicely(green('Done.'))
1160 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
1169 while next_cursor
!= 0:
1170 res
= t
.lists
.ownerships(
1171 screen_name
=g
['original_name'],
1174 next_cursor
= res
['next_cursor']
1178 printNicely(light_magenta('You own no lists :)'))
1185 name
= raw_input(light_magenta('New list\'s name: ', rl
=True))
1188 'New list\'s mode (public/private): ',
1190 description
= raw_input(
1192 'New list\'s description: ',
1198 description
=description
)
1199 printNicely(green(name
+ ' list is created.'))
1202 printNicely(red('Oops something is wrong with Twitter :('))
1211 'Your list that you want to update: ',
1215 'Update name (leave blank to unchange): ',
1217 mode
= raw_input(light_magenta('Update mode (public/private): ', rl
=True))
1218 description
= raw_input(light_magenta('Update description: ', rl
=True))
1222 slug
='-'.join(slug
.split()),
1223 owner_screen_name
=g
['original_name'],
1226 description
=description
)
1230 owner_screen_name
=g
['original_name'],
1232 description
=description
)
1233 printNicely(green(slug
+ ' list is updated.'))
1236 printNicely(red('Oops something is wrong with Twitter :('))
1245 'Your list that you want to delete: ',
1249 slug
='-'.join(slug
.split()),
1250 owner_screen_name
=g
['original_name'])
1251 printNicely(green(slug
+ ' list is deleted.'))
1254 printNicely(red('Oops something is wrong with Twitter :('))
1261 t
= Twitter(auth
=authen())
1262 # List all lists or base on action
1264 g
['list_action'] = g
['stuff'].split()[0]
1271 'all_mem': list_members
,
1272 'all_sub': list_subscribers
,
1275 'sub': list_subscribe
,
1276 'unsub': list_unsubscribe
,
1279 'update': list_update
,
1283 return action_ary
[g
['list_action']](t
)
1285 printNicely(red('Please try again.'))
1293 target
= g
['stuff'].split()[0]
1295 args
= parse_arguments()
1297 if g
['stuff'].split()[-1] == '-f':
1298 guide
= 'To ignore an option, just hit Enter key.'
1299 printNicely(light_magenta(guide
))
1300 only
= raw_input('Only nicks [Ex: @xxx,@yy]: ')
1301 ignore
= raw_input('Ignore nicks [Ex: @xxx,@yy]: ')
1302 args
.filter = filter(None, only
.split(','))
1303 args
.ignore
= filter(None, ignore
.split(','))
1305 printNicely(red('Sorry, wrong format.'))
1308 g
['stream_stop'] = True
1310 stuff
= g
['stuff'].split()[1]
1315 'public': spawn_public_stream
,
1316 'list': spawn_list_stream
,
1317 'mine': spawn_personal_stream
,
1319 spawn_dict
.get(target
)(args
, stuff
)
1322 printNicely(red('Sorry I can\'t understand.'))
1327 Unix's command `cal`
1330 rel
= os
.popen('cal').read().split('\n')
1333 show_calendar(month
, date
, rel
)
1338 List and change theme
1342 for theme
in g
['themes']:
1343 line
= light_magenta(theme
)
1344 if c
['THEME'] == theme
:
1345 line
= ' ' * 2 + light_yellow('* ') + line
1347 line
= ' ' * 4 + line
1353 c
['THEME'] = reload_theme(g
['stuff'], c
['THEME'])
1354 # Redefine decorated_name
1355 g
['decorated_name'] = lambda x
: color_func(
1356 c
['DECORATED_NAME'])(
1358 printNicely(green('Theme changed.'))
1360 printNicely(red('No such theme exists.'))
1365 Browse and change config
1367 all_config
= get_all_config()
1368 g
['stuff'] = g
['stuff'].strip()
1371 for k
in all_config
:
1373 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1375 guide
= 'Detailed explanation can be found at ' + \
1376 color_func(c
['TWEET']['link'])(
1377 'http://rainbowstream.readthedocs.org/en/latest/#config-explanation')
1379 # Print specific config
1380 elif len(g
['stuff'].split()) == 1:
1381 if g
['stuff'] in all_config
:
1384 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1387 printNicely(red('No such config key.'))
1388 # Print specific config's default value
1389 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'default':
1390 key
= g
['stuff'].split()[0]
1392 value
= get_default_config(key
)
1393 line
= ' ' * 2 + green(key
) + ': ' + light_magenta(value
)
1397 printNicely(red('Just can not get the default.'))
1398 # Delete specific config key in config file
1399 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'drop':
1400 key
= g
['stuff'].split()[0]
1403 printNicely(green('Config key is dropped.'))
1406 printNicely(red('Just can not drop the key.'))
1407 # Set specific config
1408 elif len(g
['stuff'].split()) == 3 and g
['stuff'].split()[1] == '=':
1409 key
= g
['stuff'].split()[0]
1410 value
= g
['stuff'].split()[-1]
1411 if key
== 'THEME' and not validate_theme(value
):
1412 printNicely(red('Invalid theme\'s value.'))
1415 set_config(key
, value
)
1416 # Keys that needs to be apply immediately
1418 c
['THEME'] = reload_theme(value
, c
['THEME'])
1419 g
['decorated_name'] = lambda x
: color_func(
1420 c
['DECORATED_NAME'])('[' + x
+ ']: ')
1421 elif key
== 'PREFIX':
1422 g
['PREFIX'] = u2str(emojize(format_prefix(
1423 listname
=g
['listname'],
1424 keyword
=g
['keyword']
1427 printNicely(green('Updated successfully.'))
1430 printNicely(red('Just can not set the key.'))
1432 printNicely(light_magenta('Sorry I can\'s understand.'))
1435 def help_discover():
1440 # Discover the world
1442 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1443 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1444 'You can try ' + light_green('trend US') + ' or ' + \
1445 light_green('trend JP Tokyo') + '.\n'
1446 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1447 light_green('home 7') + ' will show 7 tweets.\n'
1449 light_green('notification') + ' will show your recent notification.\n'
1450 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1451 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1452 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1453 magenta('@mdo') + '.\n'
1454 usage
+= s
* 2 + light_green('view @mdo') + \
1455 ' will show ' + magenta('@mdo') + '\'s home.\n'
1456 usage
+= s
* 2 + light_green('s AKB48') + ' will search for "' + \
1457 light_yellow('AKB48') + '" and return 5 newest tweet. ' + \
1458 'Search can be performed with or without hashtag.\n'
1469 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1470 usage
+= s
* 2 + light_green('t oops ') + \
1471 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1473 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1474 light_yellow('[id=12]') + '.\n'
1476 light_green('quote 12 ') + ' will quote the tweet with ' + \
1477 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1478 'the quote will be canceled.\n'
1480 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1481 light_yellow('[id=12]') + '.\n'
1482 usage
+= s
* 2 + light_green('conversation 12') + ' will show the chain of ' + \
1483 'replies prior to the tweet with ' + light_yellow('[id=12]') + '.\n'
1484 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1485 light_yellow('oops') + '" to the owner of the tweet with ' + \
1486 light_yellow('[id=12]') + '.\n'
1487 usage
+= s
* 2 + light_green('repall 12 oops') + ' will reply "' + \
1488 light_yellow('oops') + '" to all people in the tweet with ' + \
1489 light_yellow('[id=12]') + '.\n'
1491 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1492 light_yellow('[id=12]') + '.\n'
1494 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1495 light_yellow('[id=12]') + '.\n'
1497 light_green('share 12 ') + ' will get the direct link of the tweet with ' + \
1498 light_yellow('[id=12]') + '.\n'
1500 light_green('del 12 ') + ' will delete tweet with ' + \
1501 light_yellow('[id=12]') + '.\n'
1502 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1503 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1504 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1505 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1509 def help_messages():
1516 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1517 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1518 light_green('inbox 7') + ' will show newest 7 messages.\n'
1519 usage
+= s
* 2 + light_green('thread 2') + ' will show full thread with ' + \
1520 light_yellow('[thread_id=2]') + '.\n'
1521 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1522 magenta('@dtvd88') + '.\n'
1523 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1524 light_yellow('[message_id=5]') + '.\n'
1528 def help_friends_and_followers():
1530 Friends and Followers
1533 # Follower and following
1535 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1537 light_green('ls fl') + \
1538 ' will list all followers (people who are following you).\n'
1540 light_green('ls fr') + \
1541 ' will list all friends (people who you are following).\n'
1542 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1543 magenta('@dtvd88') + '.\n'
1544 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1545 magenta('@dtvd88') + '.\n'
1546 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1547 magenta('@dtvd88') + '.\n'
1548 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1549 magenta('@dtvd88') + '.\n'
1550 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1551 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1552 magenta('@dtvd88') + '.\n'
1553 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1554 magenta('@dtvd88') + '.\n'
1555 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1556 magenta('@dtvd88') + ' as a spam account.\n'
1567 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1568 usage
+= s
* 2 + light_green('list') + \
1569 ' will show all lists you are belong to.\n'
1570 usage
+= s
* 2 + light_green('list home') + \
1571 ' will show timeline of list. You will be asked for list\'s name.\n'
1572 usage
+= s
* 2 + light_green('list all_mem') + \
1573 ' will show list\'s all members.\n'
1574 usage
+= s
* 2 + light_green('list all_sub') + \
1575 ' will show list\'s all subscribers.\n'
1576 usage
+= s
* 2 + light_green('list add') + \
1577 ' will add specific person to a list owned by you.' + \
1578 ' You will be asked for list\'s name and person\'s name.\n'
1579 usage
+= s
* 2 + light_green('list rm') + \
1580 ' will remove specific person from a list owned by you.' + \
1581 ' You will be asked for list\'s name and person\'s name.\n'
1582 usage
+= s
* 2 + light_green('list sub') + \
1583 ' will subscribe you to a specific list.\n'
1584 usage
+= s
* 2 + light_green('list unsub') + \
1585 ' will unsubscribe you from a specific list.\n'
1586 usage
+= s
* 2 + light_green('list own') + \
1587 ' will show all list owned by you.\n'
1588 usage
+= s
* 2 + light_green('list new') + \
1589 ' will create a new list.\n'
1590 usage
+= s
* 2 + light_green('list update') + \
1591 ' will update a list owned by you.\n'
1592 usage
+= s
* 2 + light_green('list del') + \
1593 ' will delete a list owned by you.\n'
1604 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1605 usage
+= s
* 2 + light_green('switch public #AKB') + \
1606 ' will switch to public stream and follow "' + \
1607 light_yellow('AKB') + '" keyword.\n'
1608 usage
+= s
* 2 + light_green('switch mine') + \
1609 ' will switch to your personal stream.\n'
1610 usage
+= s
* 2 + light_green('switch mine -f ') + \
1611 ' will prompt to enter the filter.\n'
1612 usage
+= s
* 3 + light_yellow('Only nicks') + \
1613 ' filter will decide nicks will be INCLUDE ONLY.\n'
1614 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1615 ' filter will decide nicks will be EXCLUDE.\n'
1616 usage
+= s
* 2 + light_green('switch list') + \
1617 ' will switch to a Twitter list\'s stream. You will be asked for list name\n'
1626 h
, w
= os
.popen('stty size', 'r').read().split()
1629 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1630 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1631 usage
+= s
+ 'You are ' + \
1632 light_yellow('already') + ' on your personal stream.\n'
1633 usage
+= s
+ 'Any update from Twitter will show up ' + \
1634 light_yellow('immediately') + '.\n'
1635 usage
+= s
+ 'In addition, following commands are available right now:\n'
1636 # Twitter help section
1638 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1639 usage
+= s
* 2 + light_green('h discover') + \
1640 ' will show help for discover commands.\n'
1641 usage
+= s
* 2 + light_green('h tweets') + \
1642 ' will show help for tweets commands.\n'
1643 usage
+= s
* 2 + light_green('h messages') + \
1644 ' will show help for messages commands.\n'
1645 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1646 ' will show help for friends and followers commands.\n'
1647 usage
+= s
* 2 + light_green('h list') + \
1648 ' will show help for list commands.\n'
1649 usage
+= s
* 2 + light_green('h stream') + \
1650 ' will show help for stream commands.\n'
1653 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1654 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1655 'will be evaluate by Python interpreter.\n'
1656 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1657 ' for current month.\n'
1660 usage
+= s
+ grey(u
'\u266A' + ' Config \n')
1661 usage
+= s
* 2 + light_green('theme') + ' will list available theme. ' + \
1662 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1663 ' theme immediately.\n'
1664 usage
+= s
* 2 + light_green('config') + ' will list all config.\n'
1666 light_green('config ASCII_ART') + ' will output current value of ' +\
1667 light_yellow('ASCII_ART') + ' config key.\n'
1669 light_green('config TREND_MAX default') + ' will output default value of ' + \
1670 light_yellow('TREND_MAX') + ' config key.\n'
1672 light_green('config CUSTOM_CONFIG drop') + ' will drop ' + \
1673 light_yellow('CUSTOM_CONFIG') + ' config key.\n'
1675 light_green('config IMAGE_ON_TERM = true') + ' will set value of ' + \
1676 light_yellow('IMAGE_ON_TERM') + ' config key to ' + \
1677 light_yellow('True') + '.\n'
1680 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1681 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1682 usage
+= s
* 2 + light_green('p') + ' will pause the stream.\n'
1683 usage
+= s
* 2 + light_green('r') + ' will unpause the stream.\n'
1684 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1685 usage
+= s
* 2 + light_green('v') + ' will show version info.\n'
1686 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1689 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1690 usage
+= s
+ 'Have fun and hang tight! \n'
1693 'discover': help_discover
,
1694 'tweets': help_tweets
,
1695 'messages': help_messages
,
1696 'friends_and_followers': help_friends_and_followers
,
1698 'stream': help_stream
,
1703 lambda: printNicely(red('No such command.'))
1711 Pause stream display
1714 printNicely(green('Stream is paused'))
1722 printNicely(green('Stream is running back now'))
1738 printNicely(green('See you next time :)'))
1746 Reset prefix of line
1749 if c
.get('USER_JSON_ERROR'):
1750 printNicely(red('Your ~/.rainbow_config.json is messed up:'))
1751 printNicely(red('>>> ' + c
['USER_JSON_ERROR']))
1753 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1756 printNicely(str(eval(g
['cmd'])))
1809 # Handle function set
1862 return dict(zip(cmdset
, funcset
)).get(cmd
, reset
)
1867 Listen to user's input
1872 ['public', 'mine', 'list'], # switch
1891 ['image'], # show image
1893 ['fl', 'fr'], # list
1895 [i
for i
in g
['message_threads']], # sent
1920 [key
for key
in dict(get_all_config())], # config
1921 g
['themes'], # theme
1926 'friends_and_followers',
1937 init_interactive_shell(d
)
1944 # Only use PREFIX as a string with raw_input
1945 line
= raw_input(g
['decorated_name'](g
['PREFIX']))
1948 # Save cmd to compare with readline buffer
1949 g
['cmd'] = line
.strip()
1950 # Get short cmd to pass to handle function
1952 cmd
= line
.split()[0]
1955 # Lock the semaphore
1957 # Save cmd to global variable and call process
1958 g
['stuff'] = ' '.join(line
.split()[1:])
1959 # Process the command
1962 if cmd
in ['switch', 't', 'rt', 'rep']:
1966 # Release the semaphore lock
1972 printNicely(red('OMG something is wrong with Twitter right now.'))
1975 def reconn_notice():
1977 Notice when Hangup or Timeout
1979 guide
= light_magenta('You can use ') + \
1980 light_green('switch') + \
1981 light_magenta(' command to return to your stream.\n')
1982 guide
+= light_magenta('Type ') + \
1983 light_green('h stream') + \
1984 light_magenta(' for more details.')
1986 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
1990 def stream(domain
, args
, name
='Rainbow Stream'):
1996 c
['USER_DOMAIN']: name
,
1997 c
['PUBLIC_DOMAIN']: args
.track_keywords
or 'Global',
1998 c
['SITE_DOMAIN']: name
,
2001 ascii_art(art_dict
.get(domain
, name
))
2002 # These arguments are optional:
2004 timeout
=0.5, # To check g['stream_stop'] after each 0.5 s
2006 heartbeat_timeout
=c
['HEARTBEAT_TIMEOUT'] * 60)
2009 if args
.track_keywords
:
2010 query_args
['track'] = args
.track_keywords
2012 stream
= TwitterStream(
2017 if domain
== c
['USER_DOMAIN']:
2018 tweet_iter
= stream
.user(**query_args
)
2019 elif domain
== c
['SITE_DOMAIN']:
2020 tweet_iter
= stream
.site(**query_args
)
2022 if args
.track_keywords
:
2023 tweet_iter
= stream
.statuses
.filter(**query_args
)
2025 tweet_iter
= stream
.statuses
.sample()
2026 # Block new stream until other one exits
2027 StreamLock
.acquire()
2028 g
['stream_stop'] = False
2029 last_tweet_time
= time
.time()
2030 for tweet
in tweet_iter
:
2032 printNicely('-- None --')
2033 elif tweet
is Timeout
:
2034 # Because the stream check for each 0.3s
2035 # so we shouldn't output anything here
2036 if(g
['stream_stop']):
2037 StreamLock
.release()
2039 elif tweet
is HeartbeatTimeout
:
2040 printNicely('-- Heartbeat Timeout --')
2042 StreamLock
.release()
2044 elif tweet
is Hangup
:
2045 printNicely('-- Hangup --')
2047 StreamLock
.release()
2049 elif tweet
.get('text'):
2050 # Slow down the stream by STREAM_DELAY config key
2051 if time
.time() - last_tweet_time
< c
['STREAM_DELAY']:
2053 last_tweet_time
= time
.time()
2054 # Check the semaphore pause and lock (stream process only)
2062 keyword
=args
.track_keywords
,
2067 # Current readline buffer
2068 current_buffer
= readline
.get_line_buffer().strip()
2069 # There is an unexpected behaviour in MacOSX readline + Python 2:
2070 # after completely delete a word after typing it,
2071 # somehow readline buffer still contains
2072 # the 1st character of that word
2073 if current_buffer
and g
['cmd'] != current_buffer
:
2075 g
['decorated_name'](g
['PREFIX']) + current_buffer
)
2077 elif not c
['HIDE_PROMPT']:
2078 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2080 elif tweet
.get('direct_message'):
2081 # Check the semaphore pause and lock (stream process only)
2086 print_message(tweet
['direct_message'])
2087 elif tweet
.get('event'):
2088 c
['events'].append(tweet
)
2090 except TwitterHTTPError
as e
:
2093 magenta('We have connection problem with twitter stream API right now :('))
2094 detail_twitter_error(e
)
2095 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2099 magenta('There seems to be a connection problem.'))
2104 def spawn_public_stream(args
, keyword
=None):
2106 Spawn a new public stream
2108 # Only set keyword if specified
2110 if keyword
[0] == '#':
2111 keyword
= keyword
[1:]
2112 args
.track_keywords
= keyword
2113 g
['keyword'] = keyword
2115 g
['keyword'] = 'Global'
2116 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
2119 th
= threading
.Thread(
2128 def spawn_list_stream(args
, stuff
=None):
2130 Spawn a new list stream
2133 owner
, slug
= check_slug(stuff
)
2135 owner
, slug
= get_slug()
2137 # Force python 2 not redraw readline buffer
2138 listname
= '/'.join([owner
, slug
])
2139 # Set the listname variable
2140 # and reset tracked keyword
2141 g
['listname'] = listname
2143 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
2144 listname
=g
['listname']
2146 printNicely(light_yellow('getting list members ...'))
2148 t
= Twitter(auth
=authen())
2151 while next_cursor
!= 0:
2152 m
= t
.lists
.members(
2154 owner_screen_name
=owner
,
2156 include_entities
=False)
2157 for u
in m
['users']:
2158 members
.append('@' + u
['screen_name'])
2159 next_cursor
= m
['next_cursor']
2160 printNicely(light_yellow('... done.'))
2161 # Build thread filter array
2162 args
.filter = members
2164 th
= threading
.Thread(
2174 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
2176 printNicely(red('Ignore: ' + str(len(args
.ignore
)) + ' people.'))
2180 def spawn_personal_stream(args
, stuff
=None):
2182 Spawn a new personal stream
2184 # Reset the tracked keyword and listname
2185 g
['keyword'] = g
['listname'] = ''
2187 g
['PREFIX'] = u2str(emojize(format_prefix()))
2189 th
= threading
.Thread(
2194 g
['original_name']))
2204 args
= parse_arguments()
2208 # Twitter API connection problem
2209 except TwitterHTTPError
as e
:
2212 magenta('We have connection problem with twitter REST API right now :('))
2213 detail_twitter_error(e
)
2216 # Proxy connection problem
2217 except (socks
.ProxyConnectionError
, URLError
):
2219 magenta('There seems to be a connection problem.'))
2221 magenta('You might want to check your proxy settings (host, port and type)!'))
2225 # Spawn stream thread
2226 target
= args
.stream
.split()[0]
2227 if target
== 'mine' :
2228 spawn_personal_stream(args
)
2231 stuff
= args
.stream
.split()[1]
2235 'public': spawn_public_stream
,
2236 'list': spawn_list_stream
,
2238 spawn_dict
.get(target
)(args
, stuff
)
2240 # Start listen process