2 Colorful user's timeline stream
4 from multiprocessing
import Process
15 from twitter
.stream
import TwitterStream
, Timeout
, HeartbeatTimeout
, Hangup
16 from twitter
.api
import *
17 from twitter
.oauth
import OAuth
, read_token_file
18 from twitter
.oauth_dance
import oauth_dance
19 from twitter
.util
import printNicely
20 from StringIO
import StringIO
25 from .consumer
import *
26 from .interactive
import *
28 from .c_image
import *
72 def parse_arguments():
76 parser
= argparse
.ArgumentParser(description
=__doc__
or "")
80 help='Timeout for the stream (seconds).')
83 '--heartbeat-timeout',
84 help='Set heartbeat timeout.',
90 help='Set stream to non-blocking.')
94 help='Search the stream for specific text.')
98 help='Filter specific screen_name.')
102 help='Ignore specific screen_name.')
107 help='Display all image on terminal.')
108 return parser
.parse_args()
113 Authenticate with Twitter OAuth
115 # When using rainbow stream you must authorize.
116 twitter_credential
= os
.environ
.get(
120 '')) + os
.sep
+ '.rainbow_oauth'
121 if not os
.path
.exists(twitter_credential
):
122 oauth_dance("Rainbow Stream",
126 oauth_token
, oauth_token_secret
= read_token_file(twitter_credential
)
134 def get_decorated_name():
136 Beginning of every line
138 t
= Twitter(auth
=authen())
139 name
= '@' + t
.account
.verify_credentials()['screen_name']
140 g
['original_name'] = name
[1:]
141 g
['decorated_name'] = color_func(c
['DECORATED_NAME'])('[' + name
+ ']: ')
142 g
['ascii_art'] = True
144 files
= os
.listdir(os
.path
.dirname(__file__
)+'/colorset')
145 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
148 db
.theme_store(c
['theme'])
156 target
= g
['stuff'].split()[0]
159 args
= parse_arguments()
161 if g
['stuff'].split()[-1] == '-f':
162 only
= raw_input('Only nicks: ')
163 ignore
= raw_input('Ignore nicks: ')
164 args
.filter = filter(None, only
.split(','))
165 args
.ignore
= filter(None, ignore
.split(','))
166 elif g
['stuff'].split()[-1] == '-d':
167 args
.filter = c
['ONLY_LIST']
168 args
.ignore
= c
['IGNORE_LIST']
170 printNicely(red('Sorry, wrong format.'))
174 if target
== 'public':
175 keyword
= g
['stuff'].split()[1]
176 if keyword
[0] == '#':
177 keyword
= keyword
[1:]
179 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
180 args
.track_keywords
= keyword
188 g
['stream_pid'] = p
.pid
191 elif target
== 'mine':
193 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
202 g
['stream_pid'] = p
.pid
205 printNicely(cyan('Only: ' + str(args
.filter)))
207 printNicely(red('Ignore: ' + str(args
.ignore
)))
209 g
['ascii_art'] = True
211 printNicely(red('Sorry I can\'t understand.'))
218 t
= Twitter(auth
=authen())
219 # Get country and town
221 country
= g
['stuff'].split()[0]
225 town
= g
['stuff'].split()[1]
229 avail
= t
.trends
.available()
232 trends
= t
.trends
.place(_id
=1)[0]['trends']
235 for location
in avail
:
236 # Search for country and Town
238 if location
['countryCode'] == country \
239 and location
['placeType']['name'] == 'Town' \
240 and location
['name'] == town
:
241 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
243 # Search for country only
245 if location
['countryCode'] == country \
246 and location
['placeType']['name'] == 'Country':
247 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
255 t
= Twitter(auth
=authen())
256 num
= c
['HOME_TWEET_NUM']
257 if g
['stuff'].isdigit():
258 num
= int(g
['stuff'])
259 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
260 draw(t
=tweet
, iot
=g
['iot'])
268 t
= Twitter(auth
=authen())
269 user
= g
['stuff'].split()[0]
272 num
= int(g
['stuff'].split()[1])
274 num
= c
['HOME_TWEET_NUM']
275 for tweet
in reversed(t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
276 draw(t
=tweet
, iot
=g
['iot'])
279 printNicely(red('A name should begin with a \'@\''))
286 t
= Twitter(auth
=authen())
287 num
= c
['HOME_TWEET_NUM']
288 if g
['stuff'].isdigit():
289 num
= int(g
['stuff'])
290 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
291 draw(t
=tweet
, iot
=g
['iot'])
299 t
= Twitter(auth
=authen())
300 t
.statuses
.update(status
=g
['stuff'])
307 t
= Twitter(auth
=authen())
309 id = int(g
['stuff'].split()[0])
311 printNicely(red('Sorry I can\'t understand.'))
313 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
314 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
321 t
= Twitter(auth
=authen())
323 id = int(g
['stuff'].split()[0])
325 printNicely(red('Sorry I can\'t understand.'))
327 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
328 tweet
= t
.statuses
.show(id=tid
)
329 screen_name
= tweet
['user']['screen_name']
331 quote
= '\"@' + screen_name
+ ': ' + text
+ '\"'
332 quote
= quote
.encode('utf8')
333 notice
= light_magenta('Compose mode ')
334 notice
+= light_yellow('(Enter nothing will cancel the quote)')
335 notice
+= light_magenta(':')
337 extra
= raw_input(quote
)
339 t
.statuses
.update(status
=quote
+extra
)
341 printNicely(light_magenta('No text added.'))
348 t
= Twitter(auth
=authen())
351 id = int(g
['stuff'].split()[0])
353 printNicely(red('Sorry I can\'t understand.'))
355 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
356 # Get display num if exist
358 num
= int(g
['stuff'].split()[1])
360 num
= c
['RETWEETS_SHOW_NUM']
361 # Get result and display
362 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
364 printNicely(magenta('This tweet has no retweet.'))
366 for tweet
in reversed(rt_ary
):
367 draw(t
=tweet
, iot
=g
['iot'])
375 t
= Twitter(auth
=authen())
377 id = int(g
['stuff'].split()[0])
379 printNicely(red('Sorry I can\'t understand.'))
381 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
382 t
.favorites
.create(_id
=tid
, include_entities
=False)
383 printNicely(green('Favorited.'))
384 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
392 t
= Twitter(auth
=authen())
394 id = int(g
['stuff'].split()[0])
396 printNicely(red('Sorry I can\'t understand.'))
398 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
399 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
400 status
= ' '.join(g
['stuff'].split()[1:])
401 status
= '@' + user
+ ' ' + status
.decode('utf-8')
402 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
409 t
= Twitter(auth
=authen())
411 rid
= int(g
['stuff'].split()[0])
413 printNicely(red('Sorry I can\'t understand.'))
415 tid
= db
.rainbow_to_tweet_query(rid
)[0].tweet_id
416 t
.statuses
.destroy(id=tid
)
417 printNicely(green('Okay it\'s gone.'))
424 t
= Twitter(auth
=authen())
426 id = int(g
['stuff'].split()[0])
428 printNicely(red('Sorry I can\'t understand.'))
430 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
431 t
.favorites
.destroy(_id
=tid
)
432 printNicely(green('Okay it\'s unfavorited.'))
433 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
441 t
= Twitter(auth
=authen())
442 if g
['stuff'].startswith('#'):
443 rel
= t
.search
.tweets(q
=g
['stuff'])['statuses']
445 printNicely('Newest tweets:')
446 for i
in reversed(xrange(c
['SEARCH_MAX_RECORD'])):
449 keyword
=g
['stuff'].strip()[1:])
452 printNicely(magenta('I\'m afraid there is no result'))
454 printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
459 Send a direct message
461 t
= Twitter(auth
=authen())
462 user
= g
['stuff'].split()[0]
463 if user
[0].startswith('@'):
465 content
= g
['stuff'].split()[1]
467 printNicely(red('Sorry I can\'t understand.'))
468 t
.direct_messages
.new(
469 screen_name
=user
[1:],
472 printNicely(green('Message sent.'))
474 printNicely(red('A name should begin with a \'@\''))
481 t
= Twitter(auth
=authen())
483 target
= g
['stuff'].split()[0]
484 if target
!= 'image':
486 id = int(g
['stuff'].split()[1])
487 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
488 tweet
= t
.statuses
.show(id=tid
)
489 media
= tweet
['entities']['media']
491 res
= requests
.get(m
['media_url'])
492 img
= Image
.open(StringIO(res
.content
))
495 printNicely(red('Sorry I can\'t show this image.'))
502 t
= Twitter(auth
=authen())
504 if not g
['stuff'].isdigit():
506 tid
= db
.rainbow_to_tweet_query(g
['stuff'])[0].tweet_id
507 tweet
= t
.statuses
.show(id=tid
)
508 link_ary
= [u
for u
in tweet
['text'].split() if u
.startswith('http://')]
510 printNicely(light_magenta('No url here @.@!'))
512 for link
in link_ary
:
513 webbrowser
.open(link
)
515 printNicely(red('Sorry I can\'t open url in this tweet.'))
520 List friends for followers
522 t
= Twitter(auth
=authen())
525 name
= g
['stuff'].split()[1]
526 if name
.startswith('@'):
529 printNicely(red('A name should begin with a \'@\''))
530 raise Exception('Invalid name')
532 name
= g
['original_name']
533 # Get list followers or friends
535 target
= g
['stuff'].split()[0]
537 printNicely(red('Omg some syntax is wrong.'))
539 d
= {'fl': 'followers', 'fr': 'friends'}
543 while next_cursor
!= 0:
544 list = getattr(t
, d
[target
]).list(
548 include_entities
=False,
550 for u
in list['users']:
551 rel
[u
['name']] = '@' + u
['screen_name']
552 next_cursor
= list['next_cursor']
554 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
556 user
= ' ' + cycle_color(name
)
557 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
563 Inbox direct messages
565 t
= Twitter(auth
=authen())
566 num
= c
['MESSAGES_DISPLAY']
568 if g
['stuff'].isdigit():
571 # Max message per page is 20 so we have to loop
573 rel
= rel
+ t
.direct_messages(
576 include_entities
=False,
581 rel
= rel
+ t
.direct_messages(
584 include_entities
=False,
588 printNicely('Inbox: newest ' + str(len(rel
)) + ' messages.')
589 for m
in reversed(rel
):
598 t
= Twitter(auth
=authen())
599 num
= c
['MESSAGES_DISPLAY']
601 if g
['stuff'].isdigit():
602 num
= int(g
['stuff'])
604 # Max message per page is 20 so we have to loop
606 rel
= rel
+ t
.direct_messages
.sent(
609 include_entities
=False,
614 rel
= rel
+ t
.direct_messages
.sent(
617 include_entities
=False,
621 printNicely('Sent: newest ' + str(len(rel
)) + ' messages.')
622 for m
in reversed(rel
):
631 t
= Twitter(auth
=authen())
633 rid
= int(g
['stuff'].split()[0])
635 printNicely(red('Sorry I can\'t understand.'))
636 mid
= db
.rainbow_to_message_query(rid
)[0].message_id
637 t
.direct_messages
.destroy(id=mid
)
638 printNicely(green('Message deleted.'))
643 Show profile of a specific user
645 t
= Twitter(auth
=authen())
646 screen_name
= g
['stuff'].split()[0]
647 if screen_name
.startswith('@'):
650 screen_name
=screen_name
[1:],
651 include_entities
=False)
652 show_profile(user
, g
['iot'])
654 printNicely(red('Omg no user.'))
656 printNicely(red('A name should begin with a \'@\''))
663 t
= Twitter(auth
=authen())
664 screen_name
= g
['stuff'].split()[0]
665 if screen_name
.startswith('@'):
666 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
667 printNicely(green('You are following ' + screen_name
+ ' now!'))
669 printNicely(red('A name should begin with a \'@\''))
676 t
= Twitter(auth
=authen())
677 screen_name
= g
['stuff'].split()[0]
678 if screen_name
.startswith('@'):
679 t
.friendships
.destroy(
680 screen_name
=screen_name
[1:],
681 include_entities
=False)
682 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
684 printNicely(red('A name should begin with a \'@\''))
691 t
= Twitter(auth
=authen())
693 screen_name
= g
['stuff'].split()[0]
695 printNicely(red('A name should be specified. '))
697 if screen_name
.startswith('@'):
698 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
699 if isinstance(rel
, dict):
700 printNicely(green(screen_name
+ ' is muted.'))
702 printNicely(red(rel
))
704 printNicely(red('A name should begin with a \'@\''))
711 t
= Twitter(auth
=authen())
713 screen_name
= g
['stuff'].split()[0]
715 printNicely(red('A name should be specified. '))
717 if screen_name
.startswith('@'):
718 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
719 if isinstance(rel
, dict):
720 printNicely(green(screen_name
+ ' is unmuted.'))
722 printNicely(red(rel
))
724 printNicely(red('A name should begin with a \'@\''))
731 t
= Twitter(auth
=authen())
736 while next_cursor
!= 0:
737 list = t
.mutes
.users
.list(
738 screen_name
=g
['original_name'],
741 include_entities
=False,
743 for u
in list['users']:
744 rel
[u
['name']] = '@' + u
['screen_name']
745 next_cursor
= list['next_cursor']
747 printNicely('All: ' + str(len(rel
)) + ' people.')
749 user
= ' ' + cycle_color(name
)
750 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
758 t
= Twitter(auth
=authen())
759 screen_name
= g
['stuff'].split()[0]
760 if screen_name
.startswith('@'):
762 screen_name
=screen_name
[1:],
763 include_entities
=False,
765 printNicely(green('You blocked ' + screen_name
+ '.'))
767 printNicely(red('A name should begin with a \'@\''))
774 t
= Twitter(auth
=authen())
775 screen_name
= g
['stuff'].split()[0]
776 if screen_name
.startswith('@'):
778 screen_name
=screen_name
[1:],
779 include_entities
=False,
781 printNicely(green('Unblock ' + screen_name
+ ' success!'))
783 printNicely(red('A name should begin with a \'@\''))
788 Report a user as a spam account
790 t
= Twitter(auth
=authen())
791 screen_name
= g
['stuff'].split()[0]
792 if screen_name
.startswith('@'):
794 screen_name
=screen_name
[1:])
795 printNicely(green('You reported ' + screen_name
+ '.'))
797 printNicely(red('Sorry I can\'t understand.'))
804 rel
= t
.lists
.list(screen_name
=g
['original_name'])
808 printNicely(light_magenta('You belong to no lists :)'))
816 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
818 printNicely(light_magenta('No list specified.'))
821 l
= db
.list_name_to_id_query(list_name
)[0]
822 res
= t
.lists
.statuses(
824 count
= c
['LIST_MAX'],
825 include_entities
=False)
836 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
838 printNicely(light_magenta('No list specified.'))
841 l
= db
.list_name_to_id_query(list_name
)[0]
844 while next_cursor
!= 0 :
847 cursor
= next_cursor
,
848 include_entities
=False)
850 rel
[u
['name']] = '@' + u
['screen_name']
851 next_cursor
= m
['next_cursor']
852 printNicely('All: ' + str(len(rel
)) + ' members.')
854 user
= ' ' + cycle_color(name
)
855 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
859 def list_subscribers(t
):
864 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
866 printNicely(light_magenta('No list specified.'))
869 l
= db
.list_name_to_id_query(list_name
)[0]
872 while next_cursor
!= 0 :
873 m
= t
.lists
.subscribers(
875 cursor
= next_cursor
,
876 include_entities
=False)
878 rel
[u
['name']] = '@' + u
['screen_name']
879 next_cursor
= m
['next_cursor']
880 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
882 user
= ' ' + cycle_color(name
)
883 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
889 Remove specific user from a list
892 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
894 printNicely(light_magenta('No list specified.'))
897 l
= db
.list_name_to_id_query(list_name
)[0]
898 user_name
= raw_input(light_magenta('Give me the name of unlucky man: '))
900 t
.lists
.members
.destroy(
902 screen_name
= user_name
)
903 printNicely(light_green('Okay he\'s gone :)'))
905 printNicely(light_magenta('I\'m sorry we can not remove him.'))
912 t
= Twitter(auth
=authen())
913 # List all lists or base on action
915 g
['list_action'] = g
['stuff'].split()[0]
923 'all_mem': list_members
,
924 'all_sub': list_subscribers
,
928 return action_ary
[g
['list_action']](t
)
930 printNicely(red('Sorry I can\'t understand.'))
938 rel
= os
.popen('cal').read().split('\n')
941 show_calendar(month
, date
, rel
)
946 List and change theme
950 for theme
in g
['themes']:
952 # Detect custom config
953 if theme
== 'custom':
954 line
+= light_magenta('custom')
955 custom_path
= os
.environ
.get(
957 os
.environ
.get('USERPROFILE',
958 '')) + os
.sep
+ '.rainbow_config.json'
959 if not os
.path
.exists(custom_path
):
960 line
+= light_magenta(' (create your own config file at ~/.rainbow_config.json)')
962 line
+= light_magenta(' (loaded)')
964 line
+= light_magenta(theme
)
965 if c
['theme'] == theme
:
966 line
= ' '*2 + light_yellow('* ') + line
970 elif g
['stuff'] == 'current_as_default':
972 path
= os
.path
.dirname(__file__
) + '/colorset/init'
976 os
.system('chmod 777 ' + path
)
977 printNicely(light_green('Okay it will be applied from next time :)'))
982 if g
['stuff'] != 'custom':
983 new_config
= os
.path
.dirname(__file__
) + '/colorset/' + g
['stuff'] + '.json'
985 new_config
= os
.environ
.get(
986 'HOME',os
.environ
.get(
988 '')) + os
.sep
+ '.rainbow_config.json'
989 new_config
= load_config(new_config
)
991 for nc
in new_config
:
992 c
[nc
] = new_config
[nc
]
993 # Update db and reset colors
994 db
.theme_update(g
['stuff'])
995 c
['theme'] = g
['stuff']
997 g
['decorated_name'] = color_func(
998 c
['DECORATED_NAME'])(
999 '[@' + g
['original_name'] + ']: ')
1000 printNicely(green('Theme changed.'))
1002 if g
['stuff'] == 'custom':
1003 printNicely(red('~/.rainbow_config.json is not exists!'))
1005 printNicely(red('No such theme exists.'))
1008 def help_discover():
1013 # Discover the world
1015 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1016 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1017 'You can try ' + light_green('trend US') + ' or ' + \
1018 light_green('trend JP Tokyo') + '.\n'
1019 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1020 light_green('home 7') + ' will show 7 tweets.\n'
1021 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1022 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1023 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1024 magenta('@mdo') + '.\n'
1025 usage
+= s
* 2 + light_green('view @mdo') + \
1026 ' will show ' + magenta('@mdo') + '\'s home.\n'
1027 usage
+= s
* 2 + light_green('s #AKB48') + ' will search for "' + \
1028 light_yellow('AKB48') + '" and return 5 newest tweet.\n'
1039 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1040 usage
+= s
* 2 + light_green('t oops ') + \
1041 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1043 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1044 light_yellow('[id=12]') + '.\n'
1046 light_green('quote 12 ') + ' will quote the tweet with ' + \
1047 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1048 'the quote will be canceled.\n'
1050 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1051 light_yellow('[id=12]') + '.\n'
1052 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1053 light_yellow('oops') + '" to tweet with ' + \
1054 light_yellow('[id=12]') + '.\n'
1056 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1057 light_yellow('[id=12]') + '.\n'
1059 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1060 light_yellow('[id=12]') + '.\n'
1062 light_green('del 12 ') + ' will delete tweet with ' + \
1063 light_yellow('[id=12]') + '.\n'
1064 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1065 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1066 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1067 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1071 def help_messages():
1078 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1079 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1080 light_green('inbox 7') + ' will show newest 7 messages.\n'
1081 usage
+= s
* 2 + light_green('sent') + ' will show sent messages. ' + \
1082 light_green('sent 7') + ' will show newest 7 messages.\n'
1083 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1084 magenta('@dtvd88') + '.\n'
1085 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1086 light_yellow('[message_id=5]') + '.\n'
1090 def help_friends_and_followers():
1092 Friends and Followers
1095 # Follower and following
1097 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1099 light_green('ls fl') + \
1100 ' will list all followers (people who are following you).\n'
1102 light_green('ls fr') + \
1103 ' will list all friends (people who you are following).\n'
1104 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1105 magenta('@dtvd88') + '.\n'
1106 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1107 magenta('@dtvd88') + '.\n'
1108 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1109 magenta('@dtvd88') + '.\n'
1110 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1111 magenta('@dtvd88') + '.\n'
1112 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1113 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1114 magenta('@dtvd88') + '.\n'
1115 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1116 magenta('@dtvd88') + '.\n'
1117 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1118 magenta('@dtvd88') + ' as a spam account.\n'
1129 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1130 usage
+= s
* 2 + light_green('list') + \
1131 ' will show all lists you are belong to.\n'
1132 usage
+= s
* 2 + light_green('list home') + \
1133 ' will show timeline of list. You will be asked for list\'s name\n'
1134 usage
+= s
* 2 + light_green('list mem') + \
1135 ' will show list\'s all members.\n'
1136 usage
+= s
* 2 + light_green('list sub') + \
1137 ' will show list\'s all subscribers.\n'
1138 usage
+= s
* 2 + light_green('list rm') + \
1139 ' will remove specific person from a list owned by you.' + \
1140 ' You will be asked for list\'s name and person\'s name.\n'
1151 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1152 usage
+= s
* 2 + light_green('switch public #AKB') + \
1153 ' will switch to public stream and follow "' + \
1154 light_yellow('AKB') + '" keyword.\n'
1155 usage
+= s
* 2 + light_green('switch mine') + \
1156 ' will switch to your personal stream.\n'
1157 usage
+= s
* 2 + light_green('switch mine -f ') + \
1158 ' will prompt to enter the filter.\n'
1159 usage
+= s
* 3 + light_yellow('Only nicks') + \
1160 ' filter will decide nicks will be INCLUDE ONLY.\n'
1161 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1162 ' filter will decide nicks will be EXCLUDE.\n'
1163 usage
+= s
* 2 + light_green('switch mine -d') + \
1164 ' will use the config\'s ONLY_LIST and IGNORE_LIST.\n'
1173 h
, w
= os
.popen('stty size', 'r').read().split()
1177 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1178 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1179 usage
+= s
+ 'You are ' + \
1180 light_yellow('already') + ' on your personal stream.\n'
1181 usage
+= s
+ 'Any update from Twitter will show up ' + \
1182 light_yellow('immediately') + '.\n'
1183 usage
+= s
+ 'In addtion, following commands are available right now:\n'
1185 # Twitter help section
1187 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1188 usage
+= s
* 2 + light_green('h discover') + \
1189 ' will show help for discover commands.\n'
1190 usage
+= s
* 2 + light_green('h tweets') + \
1191 ' will show help for tweets commands.\n'
1192 usage
+= s
* 2 + light_green('h messages') + \
1193 ' will show help for messages commands.\n'
1194 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1195 ' will show help for friends and followers commands.\n'
1196 usage
+= s
* 2 + light_green('h list') + \
1197 ' will show help for list commands.\n'
1198 usage
+= s
* 2 + light_green('h stream') + \
1199 ' will show help for stream commands.\n'
1203 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1204 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1205 'will be evaluate by Python interpreter.\n'
1206 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1207 ' for current month.\n'
1211 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1212 usage
+= s
* 2 + light_green('theme') + ' will list available theme.' + \
1213 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1214 ' theme immediately.\n'
1215 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1216 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1217 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1221 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1222 usage
+= s
+ 'Have fun and hang tight! \n'
1226 'discover' : help_discover
,
1227 'tweets' : help_tweets
,
1228 'messages' : help_messages
,
1229 'friends_and_followers' : help_friends_and_followers
,
1231 'stream' : help_stream
,
1234 d
[g
['stuff'].strip()]()
1251 os
.system('rm -rf rainbow.db')
1252 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
1258 Reset prefix of line
1261 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1264 printNicely(str(eval(g
['cmd'])))
1318 Listen to user's input
1323 ['public', 'mine'], # switch
1338 ['image'], # show image
1340 ['fl', 'fr'], # list
1353 ['home','all_mem','all_sub','rm'], # list
1355 g
['themes'] + ['current_as_default'], # theme
1356 ['discover','tweets','messages','friends_and_followers','list','stream'], # help
1361 init_interactive_shell(d
)
1366 line
= raw_input(g
['decorated_name'])
1370 cmd
= line
.split()[0]
1374 # Save cmd to global variable and call process
1376 g
['stuff'] = ' '.join(line
.split()[1:])
1379 printNicely(red('OMG something is wrong with Twitter right now.'))
1380 # Not redisplay prefix
1381 if cmd
in ['switch', 't', 'rt', 'rep']:
1387 def stream(domain
, args
, name
='Rainbow Stream'):
1394 c
['USER_DOMAIN']: name
,
1395 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
1396 c
['SITE_DOMAIN']: 'Site Stream',
1399 ascii_art(art_dict
[domain
])
1401 # These arguments are optional:
1403 timeout
=args
.timeout
,
1404 block
=not args
.no_block
,
1405 heartbeat_timeout
=args
.heartbeat_timeout
)
1409 if args
.track_keywords
:
1410 query_args
['track'] = args
.track_keywords
1413 stream
= TwitterStream(
1419 if domain
== c
['USER_DOMAIN']:
1420 tweet_iter
= stream
.user(**query_args
)
1421 elif domain
== c
['SITE_DOMAIN']:
1422 tweet_iter
= stream
.site(**query_args
)
1424 if args
.track_keywords
:
1425 tweet_iter
= stream
.statuses
.filter(**query_args
)
1427 tweet_iter
= stream
.statuses
.sample()
1429 # Iterate over the stream.
1430 for tweet
in tweet_iter
:
1432 printNicely("-- None --")
1433 elif tweet
is Timeout
:
1434 printNicely("-- Timeout --")
1435 elif tweet
is HeartbeatTimeout
:
1436 printNicely("-- Heartbeat Timeout --")
1437 elif tweet
is Hangup
:
1438 printNicely("-- Hangup --")
1439 elif tweet
.get('text'):
1442 iot
=args
.image_on_term
,
1443 keyword
=args
.track_keywords
,
1447 except TwitterHTTPError
:
1450 magenta("We have maximum connection problem with twitter'stream API right now :("))
1457 # Spawn stream process
1458 args
= parse_arguments()
1460 get_decorated_name()
1462 except TwitterHTTPError
:
1465 magenta("I'm afraid we have maximum connection problem with twitter right now :("))
1466 printNicely(magenta("Let's try again later."))
1468 os
.system('rm -rf rainbow.db')
1476 g
['original_name']))
1479 # Start listen process
1483 g
['stream_pid'] = p
.pid
1484 g
['iot'] = args
.image_on_term