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 # Check type of ONLY_LIST and IGNORE_LIST
246 if not isinstance(c
['ONLY_LIST'], list):
247 printNicely(red('ONLY_LIST is not a valid list value.'))
249 if not isinstance(c
['IGNORE_LIST'], list):
250 printNicely(red('IGNORE_LIST is not a valid list value.'))
251 c
['IGNORE_LIST'] = []
253 c
['IGNORE_LIST'] += build_mute_dict()
260 t
= Twitter(auth
=authen())
261 # Get country and town
263 country
= g
['stuff'].split()[0]
267 town
= g
['stuff'].split()[1]
270 avail
= t
.trends
.available()
273 trends
= t
.trends
.place(_id
=1)[0]['trends']
276 for location
in avail
:
277 # Search for country and Town
279 if location
['countryCode'] == country \
280 and location
['placeType']['name'] == 'Town' \
281 and location
['name'] == town
:
282 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
284 # Search for country only
286 if location
['countryCode'] == country \
287 and location
['placeType']['name'] == 'Country':
288 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
296 t
= Twitter(auth
=authen())
297 num
= c
['HOME_TWEET_NUM']
298 if g
['stuff'].isdigit():
299 num
= int(g
['stuff'])
300 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
310 for e
in c
['events']:
314 printNicely(magenta('Nothing at this time.'))
321 t
= Twitter(auth
=authen())
322 num
= c
['HOME_TWEET_NUM']
323 if g
['stuff'].isdigit():
324 num
= int(g
['stuff'])
325 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
332 Show profile of a specific user
334 t
= Twitter(auth
=authen())
336 screen_name
= g
['stuff'].split()[0]
338 printNicely(red('Sorry I can\'t understand.'))
340 if screen_name
.startswith('@'):
343 screen_name
=screen_name
[1:],
344 include_entities
=False)
348 printNicely(red('No user.'))
350 printNicely(red('A name should begin with a \'@\''))
357 t
= Twitter(auth
=authen())
359 user
= g
['stuff'].split()[0]
361 printNicely(red('Sorry I can\'t understand.'))
365 num
= int(g
['stuff'].split()[1])
367 num
= c
['HOME_TWEET_NUM']
368 for tweet
in reversed(
369 t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
373 printNicely(red('A name should begin with a \'@\''))
380 t
= Twitter(auth
=authen())
382 query
= g
['stuff'].strip()
384 printNicely(red('Sorry I can\'t understand.'))
386 type = c
['SEARCH_TYPE']
387 if type not in ['mixed', 'recent', 'popular']:
389 max_record
= c
['SEARCH_MAX_RECORD']
390 count
= min(max_record
, 100)
392 rel
= t
.search
.tweets(
399 printNicely('Newest tweets:')
400 for i
in reversed(xrange(count
)):
401 draw(t
=rel
[i
], keyword
=query
)
404 printNicely(magenta('I\'m afraid there is no result'))
411 t
= Twitter(auth
=authen())
412 t
.statuses
.update(status
=g
['stuff'])
419 t
= Twitter(auth
=authen())
421 id = int(g
['stuff'].split()[0])
423 printNicely(red('Sorry I can\'t understand.'))
425 tid
= c
['tweet_dict'][id]
426 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
434 t
= Twitter(auth
=authen())
436 id = int(g
['stuff'].split()[0])
438 printNicely(red('Sorry I can\'t understand.'))
440 tid
= c
['tweet_dict'][id]
441 tweet
= t
.statuses
.show(id=tid
)
443 formater
= format_quote(tweet
)
447 prefix
= light_magenta('Compose your ', rl
=True) + \
448 light_green('#comment: ', rl
=True)
449 comment
= raw_input(prefix
)
451 quote
= comment
.join(formater
.split('#comment'))
452 t
.statuses
.update(status
=quote
)
454 printNicely(light_magenta('No text added.'))
461 t
= Twitter(auth
=authen())
464 id = int(g
['stuff'].split()[0])
466 printNicely(red('Sorry I can\'t understand.'))
468 tid
= c
['tweet_dict'][id]
469 # Get display num if exist
471 num
= int(g
['stuff'].split()[1])
473 num
= c
['RETWEETS_SHOW_NUM']
474 # Get result and display
475 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
477 printNicely(magenta('This tweet has no retweet.'))
479 for tweet
in reversed(rt_ary
):
488 t
= Twitter(auth
=authen())
490 id = int(g
['stuff'].split()[0])
492 printNicely(red('Sorry I can\'t understand.'))
494 tid
= c
['tweet_dict'][id]
495 tweet
= t
.statuses
.show(id=tid
)
496 limit
= c
['CONVERSATION_MAX']
498 thread_ref
.append(tweet
)
499 prev_tid
= tweet
['in_reply_to_status_id']
500 while prev_tid
and limit
:
502 tweet
= t
.statuses
.show(id=prev_tid
)
503 prev_tid
= tweet
['in_reply_to_status_id']
504 thread_ref
.append(tweet
)
506 for tweet
in reversed(thread_ref
):
515 t
= Twitter(auth
=authen())
517 id = int(g
['stuff'].split()[0])
519 printNicely(red('Sorry I can\'t understand.'))
521 tid
= c
['tweet_dict'][id]
522 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
523 status
= ' '.join(g
['stuff'].split()[1:])
524 status
= '@' + user
+ ' ' + str2u(status
)
525 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
532 t
= Twitter(auth
=authen())
534 id = int(g
['stuff'].split()[0])
536 printNicely(red('Sorry I can\'t understand.'))
538 tid
= c
['tweet_dict'][id]
539 original_tweet
= t
.statuses
.show(id=tid
)
540 text
= original_tweet
['text']
541 nick_ary
= [original_tweet
['user']['screen_name']]
542 for user
in list(original_tweet
['entities']['user_mentions']):
543 if user
['screen_name'] not in nick_ary \
544 and user
['screen_name'] != g
['original_name']:
545 nick_ary
.append(user
['screen_name'])
546 status
= ' '.join(g
['stuff'].split()[1:])
547 status
= ' '.join(['@' + nick
for nick
in nick_ary
]) + ' ' + str2u(status
)
548 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
555 t
= Twitter(auth
=authen())
557 id = int(g
['stuff'].split()[0])
559 printNicely(red('Sorry I can\'t understand.'))
561 tid
= c
['tweet_dict'][id]
562 t
.favorites
.create(_id
=tid
, include_entities
=False)
563 printNicely(green('Favorited.'))
564 draw(t
.statuses
.show(id=tid
))
572 t
= Twitter(auth
=authen())
574 id = int(g
['stuff'].split()[0])
576 printNicely(red('Sorry I can\'t understand.'))
578 tid
= c
['tweet_dict'][id]
579 t
.favorites
.destroy(_id
=tid
)
580 printNicely(green('Okay it\'s unfavorited.'))
581 draw(t
.statuses
.show(id=tid
))
587 Copy url of a tweet to clipboard
589 t
= Twitter(auth
=authen())
591 id = int(g
['stuff'].split()[0])
592 tid
= c
['tweet_dict'][id]
594 printNicely(red('Tweet id is not valid.'))
596 tweet
= t
.statuses
.show(id=tid
)
597 url
= 'https://twitter.com/' + \
598 tweet
['user']['screen_name'] + '/status/' + str(tid
)
600 if platform
.system().lower() == 'darwin':
601 os
.system("echo '%s' | pbcopy" % url
)
602 printNicely(green('Copied tweet\'s url to clipboard.'))
604 printNicely('Direct link: ' + yellow(url
))
611 t
= Twitter(auth
=authen())
613 id = int(g
['stuff'].split()[0])
615 printNicely(red('Sorry I can\'t understand.'))
617 tid
= c
['tweet_dict'][id]
618 t
.statuses
.destroy(id=tid
)
619 printNicely(green('Okay it\'s gone.'))
626 t
= Twitter(auth
=authen())
628 target
= g
['stuff'].split()[0]
629 if target
!= 'image':
631 id = int(g
['stuff'].split()[1])
632 tid
= c
['tweet_dict'][id]
633 tweet
= t
.statuses
.show(id=tid
)
634 media
= tweet
['entities']['media']
636 res
= requests
.get(m
['media_url'])
637 img
= Image
.open(BytesIO(res
.content
))
641 printNicely(red('Sorry I can\'t show this image.'))
648 t
= Twitter(auth
=authen())
650 if not g
['stuff'].isdigit():
652 tid
= c
['tweet_dict'][int(g
['stuff'])]
653 tweet
= t
.statuses
.show(id=tid
)
654 urls
= tweet
['entities']['urls']
656 printNicely(light_magenta('No url here @.@!'))
660 expanded_url
= url
['expanded_url']
661 webbrowser
.open(expanded_url
)
664 printNicely(red('Sorry I can\'t open url in this tweet.'))
671 t
= Twitter(auth
=authen())
672 num
= c
['MESSAGES_DISPLAY']
673 if g
['stuff'].isdigit():
679 inbox
= inbox
+ t
.direct_messages(
682 include_entities
=False,
687 inbox
= inbox
+ t
.direct_messages(
690 include_entities
=False,
694 num
= c
['MESSAGES_DISPLAY']
695 if g
['stuff'].isdigit():
700 sent
= sent
+ t
.direct_messages
.sent(
703 include_entities
=False,
708 sent
= sent
+ t
.direct_messages
.sent(
711 include_entities
=False,
716 uniq_inbox
= list(set(
717 [(m
['sender_screen_name'], m
['sender']['name']) for m
in inbox
]
719 uniq_sent
= list(set(
720 [(m
['recipient_screen_name'], m
['recipient']['name']) for m
in sent
]
722 for partner
in uniq_inbox
:
723 inbox_ary
= [m
for m
in inbox
if m
['sender_screen_name'] == partner
[0]]
725 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
726 d
[partner
] = inbox_ary
+ sent_ary
727 for partner
in uniq_sent
:
730 m
for m
in sent
if m
['recipient_screen_name'] == partner
[0]]
731 g
['message_threads'] = print_threads(d
)
736 View a thread of message
739 thread_id
= int(g
['stuff'])
741 g
['message_threads'][thread_id
],
746 printNicely(red('No such thread.'))
751 Send a direct message
753 t
= Twitter(auth
=authen())
755 user
= g
['stuff'].split()[0]
756 if user
[0].startswith('@'):
757 content
= ' '.join(g
['stuff'].split()[1:])
758 t
.direct_messages
.new(
759 screen_name
=user
[1:],
762 printNicely(green('Message sent.'))
764 printNicely(red('A name should begin with a \'@\''))
767 printNicely(red('Sorry I can\'t understand.'))
774 t
= Twitter(auth
=authen())
776 id = int(g
['stuff'].split()[0])
778 printNicely(red('Sorry I can\'t understand.'))
779 mid
= c
['message_dict'][id]
780 t
.direct_messages
.destroy(id=mid
)
781 printNicely(green('Message deleted.'))
786 List friends for followers
788 t
= Twitter(auth
=authen())
791 name
= g
['stuff'].split()[1]
792 if name
.startswith('@'):
795 printNicely(red('A name should begin with a \'@\''))
796 raise Exception('Invalid name')
798 name
= g
['original_name']
799 # Get list followers or friends
801 target
= g
['stuff'].split()[0]
803 printNicely(red('Omg some syntax is wrong.'))
806 d
= {'fl': 'followers', 'fr': 'friends'}
810 while next_cursor
!= 0:
811 list = getattr(t
, d
[target
]).list(
815 include_entities
=False,
817 for u
in list['users']:
818 rel
[u
['name']] = '@' + u
['screen_name']
819 next_cursor
= list['next_cursor']
821 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
823 user
= ' ' + cycle_color(name
)
824 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
832 t
= Twitter(auth
=authen())
833 screen_name
= g
['stuff'].split()[0]
834 if screen_name
.startswith('@'):
835 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
836 printNicely(green('You are following ' + screen_name
+ ' now!'))
838 printNicely(red('A name should begin with a \'@\''))
845 t
= Twitter(auth
=authen())
846 screen_name
= g
['stuff'].split()[0]
847 if screen_name
.startswith('@'):
848 t
.friendships
.destroy(
849 screen_name
=screen_name
[1:],
850 include_entities
=False)
851 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
853 printNicely(red('A name should begin with a \'@\''))
860 t
= Twitter(auth
=authen())
862 screen_name
= g
['stuff'].split()[0]
864 printNicely(red('A name should be specified. '))
866 if screen_name
.startswith('@'):
868 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
869 if isinstance(rel
, dict):
870 printNicely(green(screen_name
+ ' is muted.'))
871 c
['IGNORE_LIST'] += [unc(screen_name
)]
872 c
['IGNORE_LIST'] = list(set(c
['IGNORE_LIST']))
874 printNicely(red(rel
))
877 printNicely(red('Something is wrong, can not mute now :('))
879 printNicely(red('A name should begin with a \'@\''))
886 t
= Twitter(auth
=authen())
888 screen_name
= g
['stuff'].split()[0]
890 printNicely(red('A name should be specified. '))
892 if screen_name
.startswith('@'):
894 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
895 if isinstance(rel
, dict):
896 printNicely(green(screen_name
+ ' is unmuted.'))
897 c
['IGNORE_LIST'].remove(screen_name
)
899 printNicely(red(rel
))
901 printNicely(red('Maybe you are not muting this person ?'))
903 printNicely(red('A name should begin with a \'@\''))
910 # Get dict of muting users
911 md
= build_mute_dict(dict_data
=True)
912 printNicely('All: ' + str(len(md
)) + ' people.')
914 user
= ' ' + cycle_color(md
[name
])
915 user
+= color_func(c
['TWEET']['nick'])(' ' + name
+ ' ')
917 # Update from Twitter
918 c
['IGNORE_LIST'] = [n
for n
in md
]
925 t
= Twitter(auth
=authen())
926 screen_name
= g
['stuff'].split()[0]
927 if screen_name
.startswith('@'):
929 screen_name
=screen_name
[1:],
930 include_entities
=False,
932 printNicely(green('You blocked ' + screen_name
+ '.'))
934 printNicely(red('A name should begin with a \'@\''))
941 t
= Twitter(auth
=authen())
942 screen_name
= g
['stuff'].split()[0]
943 if screen_name
.startswith('@'):
945 screen_name
=screen_name
[1:],
946 include_entities
=False,
948 printNicely(green('Unblock ' + screen_name
+ ' success!'))
950 printNicely(red('A name should begin with a \'@\''))
955 Report a user as a spam account
957 t
= Twitter(auth
=authen())
958 screen_name
= g
['stuff'].split()[0]
959 if screen_name
.startswith('@'):
961 screen_name
=screen_name
[1:])
962 printNicely(green('You reported ' + screen_name
+ '.'))
964 printNicely(red('Sorry I can\'t understand.'))
972 list_name
= raw_input(
973 light_magenta('Give me the list\'s name ("@owner/list_name"): ', rl
=True))
974 # Get list name and owner
976 owner
, slug
= list_name
.split('/')
977 if slug
.startswith('@'):
982 light_magenta('List name should follow "@owner/list_name" format.'))
983 raise Exception('Wrong list name')
986 def check_slug(list_name
):
990 # Get list name and owner
992 owner
, slug
= list_name
.split('/')
993 if slug
.startswith('@'):
998 light_magenta('List name should follow "@owner/list_name" format.'))
999 raise Exception('Wrong list name')
1006 rel
= t
.lists
.list(screen_name
=g
['original_name'])
1010 printNicely(light_magenta('You belong to no lists :)'))
1017 owner
, slug
= get_slug()
1018 res
= t
.lists
.statuses(
1020 owner_screen_name
=owner
,
1021 count
=c
['LIST_MAX'],
1022 include_entities
=False)
1023 for tweet
in reversed(res
):
1028 def list_members(t
):
1032 owner
, slug
= get_slug()
1036 while next_cursor
!= 0:
1037 m
= t
.lists
.members(
1039 owner_screen_name
=owner
,
1041 include_entities
=False)
1042 for u
in m
['users']:
1043 rel
[u
['name']] = '@' + u
['screen_name']
1044 next_cursor
= m
['next_cursor']
1045 printNicely('All: ' + str(len(rel
)) + ' members.')
1047 user
= ' ' + cycle_color(name
)
1048 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1052 def list_subscribers(t
):
1056 owner
, slug
= get_slug()
1060 while next_cursor
!= 0:
1061 m
= t
.lists
.subscribers(
1063 owner_screen_name
=owner
,
1065 include_entities
=False)
1066 for u
in m
['users']:
1067 rel
[u
['name']] = '@' + u
['screen_name']
1068 next_cursor
= m
['next_cursor']
1069 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
1071 user
= ' ' + cycle_color(name
)
1072 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
1078 Add specific user to a list
1080 owner
, slug
= get_slug()
1082 user_name
= raw_input(
1084 'Give me name of the newbie: ',
1086 if user_name
.startswith('@'):
1087 user_name
= user_name
[1:]
1089 t
.lists
.members
.create(
1091 owner_screen_name
=owner
,
1092 screen_name
=user_name
)
1093 printNicely(green('Added.'))
1096 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
1101 Remove specific user from a list
1103 owner
, slug
= get_slug()
1105 user_name
= raw_input(
1107 'Give me name of the unlucky one: ',
1109 if user_name
.startswith('@'):
1110 user_name
= user_name
[1:]
1112 t
.lists
.members
.destroy(
1114 owner_screen_name
=owner
,
1115 screen_name
=user_name
)
1116 printNicely(green('Gone.'))
1119 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
1122 def list_subscribe(t
):
1126 owner
, slug
= get_slug()
1129 t
.lists
.subscribers
.create(
1131 owner_screen_name
=owner
)
1132 printNicely(green('Done.'))
1136 light_magenta('I\'m sorry you can not subscribe to this list.'))
1139 def list_unsubscribe(t
):
1143 owner
, slug
= get_slug()
1146 t
.lists
.subscribers
.destroy(
1148 owner_screen_name
=owner
)
1149 printNicely(green('Done.'))
1153 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
1162 while next_cursor
!= 0:
1163 res
= t
.lists
.ownerships(
1164 screen_name
=g
['original_name'],
1167 next_cursor
= res
['next_cursor']
1171 printNicely(light_magenta('You own no lists :)'))
1178 name
= raw_input(light_magenta('New list\'s name: ', rl
=True))
1181 'New list\'s mode (public/private): ',
1183 description
= raw_input(
1185 'New list\'s description: ',
1191 description
=description
)
1192 printNicely(green(name
+ ' list is created.'))
1195 printNicely(red('Oops something is wrong with Twitter :('))
1204 'Your list that you want to update: ',
1208 'Update name (leave blank to unchange): ',
1210 mode
= raw_input(light_magenta('Update mode (public/private): ', rl
=True))
1211 description
= raw_input(light_magenta('Update description: ', rl
=True))
1215 slug
='-'.join(slug
.split()),
1216 owner_screen_name
=g
['original_name'],
1219 description
=description
)
1223 owner_screen_name
=g
['original_name'],
1225 description
=description
)
1226 printNicely(green(slug
+ ' list is updated.'))
1229 printNicely(red('Oops something is wrong with Twitter :('))
1238 'Your list that you want to delete: ',
1242 slug
='-'.join(slug
.split()),
1243 owner_screen_name
=g
['original_name'])
1244 printNicely(green(slug
+ ' list is deleted.'))
1247 printNicely(red('Oops something is wrong with Twitter :('))
1254 t
= Twitter(auth
=authen())
1255 # List all lists or base on action
1257 g
['list_action'] = g
['stuff'].split()[0]
1264 'all_mem': list_members
,
1265 'all_sub': list_subscribers
,
1268 'sub': list_subscribe
,
1269 'unsub': list_unsubscribe
,
1272 'update': list_update
,
1276 return action_ary
[g
['list_action']](t
)
1278 printNicely(red('Please try again.'))
1286 target
= g
['stuff'].split()[0]
1288 args
= parse_arguments()
1290 if g
['stuff'].split()[-1] == '-f':
1291 guide
= 'To ignore an option, just hit Enter key.'
1292 printNicely(light_magenta(guide
))
1293 only
= raw_input('Only nicks [Ex: @xxx,@yy]: ')
1294 ignore
= raw_input('Ignore nicks [Ex: @xxx,@yy]: ')
1295 args
.filter = filter(None, only
.split(','))
1296 args
.ignore
= filter(None, ignore
.split(','))
1298 printNicely(red('Sorry, wrong format.'))
1301 g
['stream_stop'] = True
1303 stuff
= g
['stuff'].split()[1]
1308 'public': spawn_public_stream
,
1309 'list': spawn_list_stream
,
1310 'mine': spawn_personal_stream
,
1312 spawn_dict
.get(target
)(args
, stuff
)
1315 printNicely(red('Sorry I can\'t understand.'))
1320 Unix's command `cal`
1323 rel
= os
.popen('cal').read().split('\n')
1326 show_calendar(month
, date
, rel
)
1331 List and change theme
1335 for theme
in g
['themes']:
1336 line
= light_magenta(theme
)
1337 if c
['THEME'] == theme
:
1338 line
= ' ' * 2 + light_yellow('* ') + line
1340 line
= ' ' * 4 + line
1346 c
['THEME'] = reload_theme(g
['stuff'], c
['THEME'])
1347 # Redefine decorated_name
1348 g
['decorated_name'] = lambda x
: color_func(
1349 c
['DECORATED_NAME'])(
1351 printNicely(green('Theme changed.'))
1353 printNicely(red('No such theme exists.'))
1358 Browse and change config
1360 all_config
= get_all_config()
1361 g
['stuff'] = g
['stuff'].strip()
1364 for k
in all_config
:
1366 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1368 guide
= 'Detailed explanation can be found at ' + \
1369 color_func(c
['TWEET']['link'])(
1370 'http://rainbowstream.readthedocs.org/en/latest/#config-explanation')
1372 # Print specific config
1373 elif len(g
['stuff'].split()) == 1:
1374 if g
['stuff'] in all_config
:
1377 green(k
) + ': ' + light_yellow(str(all_config
[k
]))
1380 printNicely(red('No such config key.'))
1381 # Print specific config's default value
1382 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'default':
1383 key
= g
['stuff'].split()[0]
1385 value
= get_default_config(key
)
1386 line
= ' ' * 2 + green(key
) + ': ' + light_magenta(value
)
1390 printNicely(red('Just can not get the default.'))
1391 # Delete specific config key in config file
1392 elif len(g
['stuff'].split()) == 2 and g
['stuff'].split()[-1] == 'drop':
1393 key
= g
['stuff'].split()[0]
1396 printNicely(green('Config key is dropped.'))
1399 printNicely(red('Just can not drop the key.'))
1400 # Set specific config
1401 elif len(g
['stuff'].split()) == 3 and g
['stuff'].split()[1] == '=':
1402 key
= g
['stuff'].split()[0]
1403 value
= g
['stuff'].split()[-1]
1404 if key
== 'THEME' and not validate_theme(value
):
1405 printNicely(red('Invalid theme\'s value.'))
1408 set_config(key
, value
)
1409 # Keys that needs to be apply immediately
1411 c
['THEME'] = reload_theme(value
, c
['THEME'])
1412 g
['decorated_name'] = lambda x
: color_func(
1413 c
['DECORATED_NAME'])('[' + x
+ ']: ')
1414 elif key
== 'PREFIX':
1415 g
['PREFIX'] = u2str(emojize(format_prefix(
1416 listname
=g
['listname'],
1417 keyword
=g
['keyword']
1420 printNicely(green('Updated successfully.'))
1423 printNicely(red('Just can not set the key.'))
1425 printNicely(light_magenta('Sorry I can\'s understand.'))
1428 def help_discover():
1433 # Discover the world
1435 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1436 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1437 'You can try ' + light_green('trend US') + ' or ' + \
1438 light_green('trend JP Tokyo') + '.\n'
1439 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1440 light_green('home 7') + ' will show 7 tweets.\n'
1442 light_green('notification') + ' will show your recent notification.\n'
1443 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1444 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1445 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1446 magenta('@mdo') + '.\n'
1447 usage
+= s
* 2 + light_green('view @mdo') + \
1448 ' will show ' + magenta('@mdo') + '\'s home.\n'
1449 usage
+= s
* 2 + light_green('s AKB48') + ' will search for "' + \
1450 light_yellow('AKB48') + '" and return 5 newest tweet. ' + \
1451 'Search can be performed with or without hashtag.\n'
1462 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1463 usage
+= s
* 2 + light_green('t oops ') + \
1464 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1466 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1467 light_yellow('[id=12]') + '.\n'
1469 light_green('quote 12 ') + ' will quote the tweet with ' + \
1470 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1471 'the quote will be canceled.\n'
1473 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1474 light_yellow('[id=12]') + '.\n'
1475 usage
+= s
* 2 + light_green('conversation 12') + ' will show the chain of ' + \
1476 'replies prior to the tweet with ' + light_yellow('[id=12]') + '.\n'
1477 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1478 light_yellow('oops') + '" to the owner of the tweet with ' + \
1479 light_yellow('[id=12]') + '.\n'
1480 usage
+= s
* 2 + light_green('repall 12 oops') + ' will reply "' + \
1481 light_yellow('oops') + '" to all people in the tweet with ' + \
1482 light_yellow('[id=12]') + '.\n'
1484 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1485 light_yellow('[id=12]') + '.\n'
1487 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1488 light_yellow('[id=12]') + '.\n'
1490 light_green('share 12 ') + ' will get the direct link of the tweet with ' + \
1491 light_yellow('[id=12]') + '.\n'
1493 light_green('del 12 ') + ' will delete tweet with ' + \
1494 light_yellow('[id=12]') + '.\n'
1495 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1496 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1497 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1498 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1502 def help_messages():
1509 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1510 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1511 light_green('inbox 7') + ' will show newest 7 messages.\n'
1512 usage
+= s
* 2 + light_green('thread 2') + ' will show full thread with ' + \
1513 light_yellow('[thread_id=2]') + '.\n'
1514 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1515 magenta('@dtvd88') + '.\n'
1516 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1517 light_yellow('[message_id=5]') + '.\n'
1521 def help_friends_and_followers():
1523 Friends and Followers
1526 # Follower and following
1528 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1530 light_green('ls fl') + \
1531 ' will list all followers (people who are following you).\n'
1533 light_green('ls fr') + \
1534 ' will list all friends (people who you are following).\n'
1535 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1536 magenta('@dtvd88') + '.\n'
1537 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1538 magenta('@dtvd88') + '.\n'
1539 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1540 magenta('@dtvd88') + '.\n'
1541 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1542 magenta('@dtvd88') + '.\n'
1543 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1544 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1545 magenta('@dtvd88') + '.\n'
1546 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1547 magenta('@dtvd88') + '.\n'
1548 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1549 magenta('@dtvd88') + ' as a spam account.\n'
1560 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1561 usage
+= s
* 2 + light_green('list') + \
1562 ' will show all lists you are belong to.\n'
1563 usage
+= s
* 2 + light_green('list home') + \
1564 ' will show timeline of list. You will be asked for list\'s name.\n'
1565 usage
+= s
* 2 + light_green('list all_mem') + \
1566 ' will show list\'s all members.\n'
1567 usage
+= s
* 2 + light_green('list all_sub') + \
1568 ' will show list\'s all subscribers.\n'
1569 usage
+= s
* 2 + light_green('list add') + \
1570 ' will add specific person to a list owned by you.' + \
1571 ' You will be asked for list\'s name and person\'s name.\n'
1572 usage
+= s
* 2 + light_green('list rm') + \
1573 ' will remove specific person from a list owned by you.' + \
1574 ' You will be asked for list\'s name and person\'s name.\n'
1575 usage
+= s
* 2 + light_green('list sub') + \
1576 ' will subscribe you to a specific list.\n'
1577 usage
+= s
* 2 + light_green('list unsub') + \
1578 ' will unsubscribe you from a specific list.\n'
1579 usage
+= s
* 2 + light_green('list own') + \
1580 ' will show all list owned by you.\n'
1581 usage
+= s
* 2 + light_green('list new') + \
1582 ' will create a new list.\n'
1583 usage
+= s
* 2 + light_green('list update') + \
1584 ' will update a list owned by you.\n'
1585 usage
+= s
* 2 + light_green('list del') + \
1586 ' will delete a list owned by you.\n'
1597 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1598 usage
+= s
* 2 + light_green('switch public #AKB') + \
1599 ' will switch to public stream and follow "' + \
1600 light_yellow('AKB') + '" keyword.\n'
1601 usage
+= s
* 2 + light_green('switch mine') + \
1602 ' will switch to your personal stream.\n'
1603 usage
+= s
* 2 + light_green('switch mine -f ') + \
1604 ' will prompt to enter the filter.\n'
1605 usage
+= s
* 3 + light_yellow('Only nicks') + \
1606 ' filter will decide nicks will be INCLUDE ONLY.\n'
1607 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1608 ' filter will decide nicks will be EXCLUDE.\n'
1609 usage
+= s
* 2 + light_green('switch list') + \
1610 ' will switch to a Twitter list\'s stream. You will be asked for list name\n'
1619 h
, w
= os
.popen('stty size', 'r').read().split()
1622 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1623 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1624 usage
+= s
+ 'You are ' + \
1625 light_yellow('already') + ' on your personal stream.\n'
1626 usage
+= s
+ 'Any update from Twitter will show up ' + \
1627 light_yellow('immediately') + '.\n'
1628 usage
+= s
+ 'In addition, following commands are available right now:\n'
1629 # Twitter help section
1631 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1632 usage
+= s
* 2 + light_green('h discover') + \
1633 ' will show help for discover commands.\n'
1634 usage
+= s
* 2 + light_green('h tweets') + \
1635 ' will show help for tweets commands.\n'
1636 usage
+= s
* 2 + light_green('h messages') + \
1637 ' will show help for messages commands.\n'
1638 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1639 ' will show help for friends and followers commands.\n'
1640 usage
+= s
* 2 + light_green('h list') + \
1641 ' will show help for list commands.\n'
1642 usage
+= s
* 2 + light_green('h stream') + \
1643 ' will show help for stream commands.\n'
1646 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1647 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1648 'will be evaluate by Python interpreter.\n'
1649 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1650 ' for current month.\n'
1653 usage
+= s
+ grey(u
'\u266A' + ' Config \n')
1654 usage
+= s
* 2 + light_green('theme') + ' will list available theme. ' + \
1655 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1656 ' theme immediately.\n'
1657 usage
+= s
* 2 + light_green('config') + ' will list all config.\n'
1659 light_green('config ASCII_ART') + ' will output current value of ' +\
1660 light_yellow('ASCII_ART') + ' config key.\n'
1662 light_green('config TREND_MAX default') + ' will output default value of ' + \
1663 light_yellow('TREND_MAX') + ' config key.\n'
1665 light_green('config CUSTOM_CONFIG drop') + ' will drop ' + \
1666 light_yellow('CUSTOM_CONFIG') + ' config key.\n'
1668 light_green('config IMAGE_ON_TERM = true') + ' will set value of ' + \
1669 light_yellow('IMAGE_ON_TERM') + ' config key to ' + \
1670 light_yellow('True') + '.\n'
1673 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1674 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1675 usage
+= s
* 2 + light_green('p') + ' will pause the stream.\n'
1676 usage
+= s
* 2 + light_green('r') + ' will unpause the stream.\n'
1677 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1678 usage
+= s
* 2 + light_green('v') + ' will show version info.\n'
1679 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1682 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1683 usage
+= s
+ 'Have fun and hang tight! \n'
1686 'discover': help_discover
,
1687 'tweets': help_tweets
,
1688 'messages': help_messages
,
1689 'friends_and_followers': help_friends_and_followers
,
1691 'stream': help_stream
,
1696 lambda: printNicely(red('No such command.'))
1704 Pause stream display
1707 printNicely(green('Stream is paused'))
1715 printNicely(green('Stream is running back now'))
1731 printNicely(green('See you next time :)'))
1739 Reset prefix of line
1742 if c
.get('USER_JSON_ERROR'):
1743 printNicely(red('Your ~/.rainbow_config.json is messed up:'))
1744 printNicely(red('>>> ' + c
['USER_JSON_ERROR']))
1746 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1749 printNicely(str(eval(g
['cmd'])))
1802 # Handle function set
1855 return dict(zip(cmdset
, funcset
)).get(cmd
, reset
)
1860 Listen to user's input
1865 ['public', 'mine', 'list'], # switch
1884 ['image'], # show image
1886 ['fl', 'fr'], # list
1888 [i
for i
in g
['message_threads']], # sent
1913 [key
for key
in dict(get_all_config())], # config
1914 g
['themes'], # theme
1919 'friends_and_followers',
1930 init_interactive_shell(d
)
1937 # Only use PREFIX as a string with raw_input
1938 line
= raw_input(g
['decorated_name'](g
['PREFIX']))
1941 # Save cmd to compare with readline buffer
1942 g
['cmd'] = line
.strip()
1943 # Get short cmd to pass to handle function
1945 cmd
= line
.split()[0]
1948 # Lock the semaphore
1950 # Save cmd to global variable and call process
1951 g
['stuff'] = ' '.join(line
.split()[1:])
1952 # Check tweet length
1953 # Process the command
1956 if cmd
in ['switch', 't', 'rt', 'rep']:
1960 # Release the semaphore lock
1964 except TwitterHTTPError
as e
:
1965 detail_twitter_error(e
)
1968 printNicely(red('OMG something is wrong with Twitter API right now.'))
1971 def reconn_notice():
1973 Notice when Hangup or Timeout
1975 guide
= light_magenta('You can use ') + \
1976 light_green('switch') + \
1977 light_magenta(' command to return to your stream.\n')
1978 guide
+= light_magenta('Type ') + \
1979 light_green('h stream') + \
1980 light_magenta(' for more details.')
1982 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
1986 def stream(domain
, args
, name
='Rainbow Stream'):
1992 c
['USER_DOMAIN']: name
,
1993 c
['PUBLIC_DOMAIN']: args
.track_keywords
or 'Global',
1994 c
['SITE_DOMAIN']: name
,
1997 ascii_art(art_dict
.get(domain
, name
))
1998 # These arguments are optional:
2000 timeout
=0.5, # To check g['stream_stop'] after each 0.5 s
2002 heartbeat_timeout
=c
['HEARTBEAT_TIMEOUT'] * 60)
2005 if args
.track_keywords
:
2006 query_args
['track'] = args
.track_keywords
2008 stream
= TwitterStream(
2013 if domain
== c
['USER_DOMAIN']:
2014 tweet_iter
= stream
.user(**query_args
)
2015 elif domain
== c
['SITE_DOMAIN']:
2016 tweet_iter
= stream
.site(**query_args
)
2018 if args
.track_keywords
:
2019 tweet_iter
= stream
.statuses
.filter(**query_args
)
2021 tweet_iter
= stream
.statuses
.sample()
2022 # Block new stream until other one exits
2023 StreamLock
.acquire()
2024 g
['stream_stop'] = False
2025 last_tweet_time
= time
.time()
2026 for tweet
in tweet_iter
:
2028 printNicely('-- None --')
2029 elif tweet
is Timeout
:
2030 # Because the stream check for each 0.3s
2031 # so we shouldn't output anything here
2032 if(g
['stream_stop']):
2033 StreamLock
.release()
2035 elif tweet
is HeartbeatTimeout
:
2036 printNicely('-- Heartbeat Timeout --')
2038 StreamLock
.release()
2040 elif tweet
is Hangup
:
2041 printNicely('-- Hangup --')
2043 StreamLock
.release()
2045 elif tweet
.get('text'):
2046 # Slow down the stream by STREAM_DELAY config key
2047 if time
.time() - last_tweet_time
< c
['STREAM_DELAY']:
2049 last_tweet_time
= time
.time()
2050 # Check the semaphore pause and lock (stream process only)
2058 keyword
=args
.track_keywords
,
2063 # Current readline buffer
2064 current_buffer
= readline
.get_line_buffer().strip()
2065 # There is an unexpected behaviour in MacOSX readline + Python 2:
2066 # after completely delete a word after typing it,
2067 # somehow readline buffer still contains
2068 # the 1st character of that word
2069 if current_buffer
and g
['cmd'] != current_buffer
:
2071 g
['decorated_name'](g
['PREFIX']) + current_buffer
)
2073 elif not c
['HIDE_PROMPT']:
2074 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2076 elif tweet
.get('direct_message'):
2077 # Check the semaphore pause and lock (stream process only)
2082 print_message(tweet
['direct_message'])
2083 elif tweet
.get('event'):
2084 c
['events'].append(tweet
)
2086 except TwitterHTTPError
as e
:
2089 magenta('We have connection problem with twitter stream API right now :('))
2090 detail_twitter_error(e
)
2091 sys
.stdout
.write(g
['decorated_name'](g
['PREFIX']))
2095 magenta('There seems to be a connection problem.'))
2100 def spawn_public_stream(args
, keyword
=None):
2102 Spawn a new public stream
2104 # Only set keyword if specified
2106 if keyword
[0] == '#':
2107 keyword
= keyword
[1:]
2108 args
.track_keywords
= keyword
2109 g
['keyword'] = keyword
2111 g
['keyword'] = 'Global'
2112 g
['PREFIX'] = u2str(emojize(format_prefix(keyword
=g
['keyword'])))
2115 th
= threading
.Thread(
2124 def spawn_list_stream(args
, stuff
=None):
2126 Spawn a new list stream
2129 owner
, slug
= check_slug(stuff
)
2131 owner
, slug
= get_slug()
2133 # Force python 2 not redraw readline buffer
2134 listname
= '/'.join([owner
, slug
])
2135 # Set the listname variable
2136 # and reset tracked keyword
2137 g
['listname'] = listname
2139 g
['PREFIX'] = g
['cmd'] = u2str(emojize(format_prefix(
2140 listname
=g
['listname']
2142 printNicely(light_yellow('getting list members ...'))
2144 t
= Twitter(auth
=authen())
2147 while next_cursor
!= 0:
2148 m
= t
.lists
.members(
2150 owner_screen_name
=owner
,
2152 include_entities
=False)
2153 for u
in m
['users']:
2154 members
.append('@' + u
['screen_name'])
2155 next_cursor
= m
['next_cursor']
2156 printNicely(light_yellow('... done.'))
2157 # Build thread filter array
2158 args
.filter = members
2160 th
= threading
.Thread(
2170 printNicely(cyan('Include: ' + str(len(args
.filter)) + ' people.'))
2172 printNicely(red('Ignore: ' + str(len(args
.ignore
)) + ' people.'))
2176 def spawn_personal_stream(args
, stuff
=None):
2178 Spawn a new personal stream
2180 # Reset the tracked keyword and listname
2181 g
['keyword'] = g
['listname'] = ''
2183 g
['PREFIX'] = u2str(emojize(format_prefix()))
2185 th
= threading
.Thread(
2190 g
['original_name']))
2200 args
= parse_arguments()
2204 # Twitter API connection problem
2205 except TwitterHTTPError
as e
:
2208 magenta('We have connection problem with twitter REST API right now :('))
2209 detail_twitter_error(e
)
2212 # Proxy connection problem
2213 except (socks
.ProxyConnectionError
, URLError
):
2215 magenta('There seems to be a connection problem.'))
2217 magenta('You might want to check your proxy settings (host, port and type)!'))
2221 # Spawn stream thread
2222 target
= args
.stream
.split()[0]
2223 if target
== 'mine':
2224 spawn_personal_stream(args
)
2227 stuff
= args
.stream
.split()[1]
2231 'public': spawn_public_stream
,
2232 'list': spawn_list_stream
,
2234 spawn_dict
.get(target
)(args
, stuff
)
2236 # Start listen process