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
24 from .consumer
import *
25 from .interactive
import *
27 from .c_image
import *
28 from .py3patch
import *
73 def parse_arguments():
77 parser
= argparse
.ArgumentParser(description
=__doc__
or "")
81 help='Timeout for the stream (seconds).')
84 '--heartbeat-timeout',
85 help='Set heartbeat timeout.',
91 help='Set stream to non-blocking.')
95 help='Search the stream for specific text.')
99 help='Filter specific screen_name.')
103 help='Ignore specific screen_name.')
108 help='Display all image on terminal.')
109 return parser
.parse_args()
114 Authenticate with Twitter OAuth
116 # When using rainbow stream you must authorize.
117 twitter_credential
= os
.environ
.get(
121 '')) + os
.sep
+ '.rainbow_oauth'
122 if not os
.path
.exists(twitter_credential
):
123 oauth_dance("Rainbow Stream",
127 oauth_token
, oauth_token_secret
= read_token_file(twitter_credential
)
135 def get_decorated_name():
137 Beginning of every line
139 t
= Twitter(auth
=authen())
140 name
= '@' + t
.account
.verify_credentials()['screen_name']
141 g
['original_name'] = name
[1:]
142 g
['decorated_name'] = color_func(c
['DECORATED_NAME'])('[' + name
+ ']: ')
143 g
['ascii_art'] = True
145 files
= os
.listdir(os
.path
.dirname(__file__
)+'/colorset')
146 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
149 db
.theme_store(c
['theme'])
157 target
= g
['stuff'].split()[0]
160 args
= parse_arguments()
162 if g
['stuff'].split()[-1] == '-f':
163 only
= raw_input('Only nicks: ')
164 ignore
= raw_input('Ignore nicks: ')
165 args
.filter = filter(None, only
.split(','))
166 args
.ignore
= filter(None, ignore
.split(','))
167 elif g
['stuff'].split()[-1] == '-d':
168 args
.filter = c
['ONLY_LIST']
169 args
.ignore
= c
['IGNORE_LIST']
171 printNicely(red('Sorry, wrong format.'))
175 if target
== 'public':
176 keyword
= g
['stuff'].split()[1]
177 if keyword
[0] == '#':
178 keyword
= keyword
[1:]
180 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
181 args
.track_keywords
= keyword
189 g
['stream_pid'] = p
.pid
192 elif target
== 'mine':
194 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
203 g
['stream_pid'] = p
.pid
206 printNicely(cyan('Only: ' + str(args
.filter)))
208 printNicely(red('Ignore: ' + str(args
.ignore
)))
210 g
['ascii_art'] = True
212 printNicely(red('Sorry I can\'t understand.'))
219 t
= Twitter(auth
=authen())
220 # Get country and town
222 country
= g
['stuff'].split()[0]
226 town
= g
['stuff'].split()[1]
230 avail
= t
.trends
.available()
233 trends
= t
.trends
.place(_id
=1)[0]['trends']
236 for location
in avail
:
237 # Search for country and Town
239 if location
['countryCode'] == country \
240 and location
['placeType']['name'] == 'Town' \
241 and location
['name'] == town
:
242 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
244 # Search for country only
246 if location
['countryCode'] == country \
247 and location
['placeType']['name'] == 'Country':
248 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
256 t
= Twitter(auth
=authen())
257 num
= c
['HOME_TWEET_NUM']
258 if g
['stuff'].isdigit():
259 num
= int(g
['stuff'])
260 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
261 draw(t
=tweet
, iot
=g
['iot'])
269 t
= Twitter(auth
=authen())
270 user
= g
['stuff'].split()[0]
273 num
= int(g
['stuff'].split()[1])
275 num
= c
['HOME_TWEET_NUM']
276 for tweet
in reversed(t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
277 draw(t
=tweet
, iot
=g
['iot'])
280 printNicely(red('A name should begin with a \'@\''))
287 t
= Twitter(auth
=authen())
288 num
= c
['HOME_TWEET_NUM']
289 if g
['stuff'].isdigit():
290 num
= int(g
['stuff'])
291 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
292 draw(t
=tweet
, iot
=g
['iot'])
300 t
= Twitter(auth
=authen())
301 t
.statuses
.update(status
=g
['stuff'])
308 t
= Twitter(auth
=authen())
310 id = int(g
['stuff'].split()[0])
312 printNicely(red('Sorry I can\'t understand.'))
314 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
315 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
322 t
= Twitter(auth
=authen())
324 id = int(g
['stuff'].split()[0])
326 printNicely(red('Sorry I can\'t understand.'))
328 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
329 tweet
= t
.statuses
.show(id=tid
)
330 screen_name
= tweet
['user']['screen_name']
332 quote
= '\"@' + screen_name
+ ': ' + text
+ '\"'
333 quote
= quote
.encode('utf8')
334 notice
= light_magenta('Compose mode ')
335 notice
+= light_yellow('(Enter nothing will cancel the quote)')
336 notice
+= light_magenta(':')
338 extra
= raw_input(quote
)
340 t
.statuses
.update(status
=quote
+extra
)
342 printNicely(light_magenta('No text added.'))
349 t
= Twitter(auth
=authen())
352 id = int(g
['stuff'].split()[0])
354 printNicely(red('Sorry I can\'t understand.'))
356 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
357 # Get display num if exist
359 num
= int(g
['stuff'].split()[1])
361 num
= c
['RETWEETS_SHOW_NUM']
362 # Get result and display
363 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
365 printNicely(magenta('This tweet has no retweet.'))
367 for tweet
in reversed(rt_ary
):
368 draw(t
=tweet
, iot
=g
['iot'])
376 t
= Twitter(auth
=authen())
378 id = int(g
['stuff'].split()[0])
380 printNicely(red('Sorry I can\'t understand.'))
382 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
383 t
.favorites
.create(_id
=tid
, include_entities
=False)
384 printNicely(green('Favorited.'))
385 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
393 t
= Twitter(auth
=authen())
395 id = int(g
['stuff'].split()[0])
397 printNicely(red('Sorry I can\'t understand.'))
399 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
400 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
401 status
= ' '.join(g
['stuff'].split()[1:])
402 status
= '@' + user
+ ' ' + status
.decode('utf-8')
403 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
410 t
= Twitter(auth
=authen())
412 rid
= int(g
['stuff'].split()[0])
414 printNicely(red('Sorry I can\'t understand.'))
416 tid
= db
.rainbow_to_tweet_query(rid
)[0].tweet_id
417 t
.statuses
.destroy(id=tid
)
418 printNicely(green('Okay it\'s gone.'))
425 t
= Twitter(auth
=authen())
427 id = int(g
['stuff'].split()[0])
429 printNicely(red('Sorry I can\'t understand.'))
431 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
432 t
.favorites
.destroy(_id
=tid
)
433 printNicely(green('Okay it\'s unfavorited.'))
434 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
442 t
= Twitter(auth
=authen())
443 if g
['stuff'].startswith('#'):
444 rel
= t
.search
.tweets(q
=g
['stuff'])['statuses']
446 printNicely('Newest tweets:')
447 for i
in reversed(xrange(c
['SEARCH_MAX_RECORD'])):
450 keyword
=g
['stuff'].strip()[1:])
453 printNicely(magenta('I\'m afraid there is no result'))
455 printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
460 Send a direct message
462 t
= Twitter(auth
=authen())
463 user
= g
['stuff'].split()[0]
464 if user
[0].startswith('@'):
466 content
= g
['stuff'].split()[1]
468 printNicely(red('Sorry I can\'t understand.'))
469 t
.direct_messages
.new(
470 screen_name
=user
[1:],
473 printNicely(green('Message sent.'))
475 printNicely(red('A name should begin with a \'@\''))
482 t
= Twitter(auth
=authen())
484 target
= g
['stuff'].split()[0]
485 if target
!= 'image':
487 id = int(g
['stuff'].split()[1])
488 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
489 tweet
= t
.statuses
.show(id=tid
)
490 media
= tweet
['entities']['media']
492 res
= requests
.get(m
['media_url'])
493 img
= Image
.open(StringIO(res
.content
))
496 printNicely(red('Sorry I can\'t show this image.'))
503 t
= Twitter(auth
=authen())
505 if not g
['stuff'].isdigit():
507 tid
= db
.rainbow_to_tweet_query(g
['stuff'])[0].tweet_id
508 tweet
= t
.statuses
.show(id=tid
)
509 link_ary
= [u
for u
in tweet
['text'].split() if u
.startswith('http://')]
511 printNicely(light_magenta('No url here @.@!'))
513 for link
in link_ary
:
514 webbrowser
.open(link
)
516 printNicely(red('Sorry I can\'t open url in this tweet.'))
521 List friends for followers
523 t
= Twitter(auth
=authen())
526 name
= g
['stuff'].split()[1]
527 if name
.startswith('@'):
530 printNicely(red('A name should begin with a \'@\''))
531 raise Exception('Invalid name')
533 name
= g
['original_name']
534 # Get list followers or friends
536 target
= g
['stuff'].split()[0]
538 printNicely(red('Omg some syntax is wrong.'))
540 d
= {'fl': 'followers', 'fr': 'friends'}
544 while next_cursor
!= 0:
545 list = getattr(t
, d
[target
]).list(
549 include_entities
=False,
551 for u
in list['users']:
552 rel
[u
['name']] = '@' + u
['screen_name']
553 next_cursor
= list['next_cursor']
555 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
557 user
= ' ' + cycle_color(name
)
558 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
564 Inbox direct messages
566 t
= Twitter(auth
=authen())
567 num
= c
['MESSAGES_DISPLAY']
569 if g
['stuff'].isdigit():
572 # Max message per page is 20 so we have to loop
574 rel
= rel
+ t
.direct_messages(
577 include_entities
=False,
582 rel
= rel
+ t
.direct_messages(
585 include_entities
=False,
589 printNicely('Inbox: newest ' + str(len(rel
)) + ' messages.')
590 for m
in reversed(rel
):
599 t
= Twitter(auth
=authen())
600 num
= c
['MESSAGES_DISPLAY']
602 if g
['stuff'].isdigit():
603 num
= int(g
['stuff'])
605 # Max message per page is 20 so we have to loop
607 rel
= rel
+ t
.direct_messages
.sent(
610 include_entities
=False,
615 rel
= rel
+ t
.direct_messages
.sent(
618 include_entities
=False,
622 printNicely('Sent: newest ' + str(len(rel
)) + ' messages.')
623 for m
in reversed(rel
):
632 t
= Twitter(auth
=authen())
634 rid
= int(g
['stuff'].split()[0])
636 printNicely(red('Sorry I can\'t understand.'))
637 mid
= db
.rainbow_to_message_query(rid
)[0].message_id
638 t
.direct_messages
.destroy(id=mid
)
639 printNicely(green('Message deleted.'))
644 Show profile of a specific user
646 t
= Twitter(auth
=authen())
647 screen_name
= g
['stuff'].split()[0]
648 if screen_name
.startswith('@'):
651 screen_name
=screen_name
[1:],
652 include_entities
=False)
653 show_profile(user
, g
['iot'])
655 printNicely(red('Omg no user.'))
657 printNicely(red('A name should begin with a \'@\''))
664 t
= Twitter(auth
=authen())
665 screen_name
= g
['stuff'].split()[0]
666 if screen_name
.startswith('@'):
667 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
668 printNicely(green('You are following ' + screen_name
+ ' now!'))
670 printNicely(red('A name should begin with a \'@\''))
677 t
= Twitter(auth
=authen())
678 screen_name
= g
['stuff'].split()[0]
679 if screen_name
.startswith('@'):
680 t
.friendships
.destroy(
681 screen_name
=screen_name
[1:],
682 include_entities
=False)
683 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
685 printNicely(red('A name should begin with a \'@\''))
692 t
= Twitter(auth
=authen())
694 screen_name
= g
['stuff'].split()[0]
696 printNicely(red('A name should be specified. '))
698 if screen_name
.startswith('@'):
699 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
700 if isinstance(rel
, dict):
701 printNicely(green(screen_name
+ ' is muted.'))
703 printNicely(red(rel
))
705 printNicely(red('A name should begin with a \'@\''))
712 t
= Twitter(auth
=authen())
714 screen_name
= g
['stuff'].split()[0]
716 printNicely(red('A name should be specified. '))
718 if screen_name
.startswith('@'):
719 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
720 if isinstance(rel
, dict):
721 printNicely(green(screen_name
+ ' is unmuted.'))
723 printNicely(red(rel
))
725 printNicely(red('A name should begin with a \'@\''))
732 t
= Twitter(auth
=authen())
737 while next_cursor
!= 0:
738 list = t
.mutes
.users
.list(
739 screen_name
=g
['original_name'],
742 include_entities
=False,
744 for u
in list['users']:
745 rel
[u
['name']] = '@' + u
['screen_name']
746 next_cursor
= list['next_cursor']
748 printNicely('All: ' + str(len(rel
)) + ' people.')
750 user
= ' ' + cycle_color(name
)
751 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
759 t
= Twitter(auth
=authen())
760 screen_name
= g
['stuff'].split()[0]
761 if screen_name
.startswith('@'):
763 screen_name
=screen_name
[1:],
764 include_entities
=False,
766 printNicely(green('You blocked ' + screen_name
+ '.'))
768 printNicely(red('A name should begin with a \'@\''))
775 t
= Twitter(auth
=authen())
776 screen_name
= g
['stuff'].split()[0]
777 if screen_name
.startswith('@'):
779 screen_name
=screen_name
[1:],
780 include_entities
=False,
782 printNicely(green('Unblock ' + screen_name
+ ' success!'))
784 printNicely(red('A name should begin with a \'@\''))
789 Report a user as a spam account
791 t
= Twitter(auth
=authen())
792 screen_name
= g
['stuff'].split()[0]
793 if screen_name
.startswith('@'):
795 screen_name
=screen_name
[1:])
796 printNicely(green('You reported ' + screen_name
+ '.'))
798 printNicely(red('Sorry I can\'t understand.'))
805 rel
= t
.lists
.list(screen_name
=g
['original_name'])
809 printNicely(light_magenta('You belong to no lists :)'))
817 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
819 printNicely(light_magenta('No list specified.'))
822 l
= db
.list_name_to_id_query(list_name
)[0]
823 res
= t
.lists
.statuses(
825 count
= c
['LIST_MAX'],
826 include_entities
=False)
837 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
839 printNicely(light_magenta('No list specified.'))
842 l
= db
.list_name_to_id_query(list_name
)[0]
845 while next_cursor
!= 0 :
848 cursor
= next_cursor
,
849 include_entities
=False)
851 rel
[u
['name']] = '@' + u
['screen_name']
852 next_cursor
= m
['next_cursor']
853 printNicely('All: ' + str(len(rel
)) + ' members.')
855 user
= ' ' + cycle_color(name
)
856 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
860 def list_subscribers(t
):
865 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
867 printNicely(light_magenta('No list specified.'))
870 l
= db
.list_name_to_id_query(list_name
)[0]
873 while next_cursor
!= 0 :
874 m
= t
.lists
.subscribers(
876 cursor
= next_cursor
,
877 include_entities
=False)
879 rel
[u
['name']] = '@' + u
['screen_name']
880 next_cursor
= m
['next_cursor']
881 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
883 user
= ' ' + cycle_color(name
)
884 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
890 Remove specific user from a list
893 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
895 printNicely(light_magenta('No list specified.'))
898 l
= db
.list_name_to_id_query(list_name
)[0]
899 user_name
= raw_input(light_magenta('Give me the name of unlucky man: '))
901 t
.lists
.members
.destroy(
903 screen_name
= user_name
)
904 printNicely(light_green('Okay he\'s gone :)'))
906 printNicely(light_magenta('I\'m sorry we can not remove him.'))
913 t
= Twitter(auth
=authen())
914 # List all lists or base on action
916 g
['list_action'] = g
['stuff'].split()[0]
924 'all_mem': list_members
,
925 'all_sub': list_subscribers
,
929 return action_ary
[g
['list_action']](t
)
931 printNicely(red('Sorry I can\'t understand.'))
939 rel
= os
.popen('cal').read().split('\n')
942 show_calendar(month
, date
, rel
)
947 List and change theme
951 for theme
in g
['themes']:
953 # Detect custom config
954 if theme
== 'custom':
955 line
+= light_magenta('custom')
956 custom_path
= os
.environ
.get(
958 os
.environ
.get('USERPROFILE',
959 '')) + os
.sep
+ '.rainbow_config.json'
960 if not os
.path
.exists(custom_path
):
961 line
+= light_magenta(' (create your own config file at ~/.rainbow_config.json)')
963 line
+= light_magenta(' (loaded)')
965 line
+= light_magenta(theme
)
966 if c
['theme'] == theme
:
967 line
= ' '*2 + light_yellow('* ') + line
971 elif g
['stuff'] == 'current_as_default':
973 path
= os
.path
.dirname(__file__
) + '/colorset/init'
977 os
.system('chmod 777 ' + path
)
978 printNicely(light_green('Okay it will be applied from next time :)'))
983 if g
['stuff'] != 'custom':
984 new_config
= os
.path
.dirname(__file__
) + '/colorset/' + g
['stuff'] + '.json'
986 new_config
= os
.environ
.get(
987 'HOME',os
.environ
.get(
989 '')) + os
.sep
+ '.rainbow_config.json'
990 new_config
= load_config(new_config
)
992 for nc
in new_config
:
993 c
[nc
] = new_config
[nc
]
994 # Update db and reset colors
995 db
.theme_update(g
['stuff'])
996 c
['theme'] = g
['stuff']
998 g
['decorated_name'] = color_func(
999 c
['DECORATED_NAME'])(
1000 '[@' + g
['original_name'] + ']: ')
1001 printNicely(green('Theme changed.'))
1003 if g
['stuff'] == 'custom':
1004 printNicely(red('~/.rainbow_config.json is not exists!'))
1006 printNicely(red('No such theme exists.'))
1009 def help_discover():
1014 # Discover the world
1016 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1017 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1018 'You can try ' + light_green('trend US') + ' or ' + \
1019 light_green('trend JP Tokyo') + '.\n'
1020 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1021 light_green('home 7') + ' will show 7 tweets.\n'
1022 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1023 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1024 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1025 magenta('@mdo') + '.\n'
1026 usage
+= s
* 2 + light_green('view @mdo') + \
1027 ' will show ' + magenta('@mdo') + '\'s home.\n'
1028 usage
+= s
* 2 + light_green('s #AKB48') + ' will search for "' + \
1029 light_yellow('AKB48') + '" and return 5 newest tweet.\n'
1040 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1041 usage
+= s
* 2 + light_green('t oops ') + \
1042 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1044 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1045 light_yellow('[id=12]') + '.\n'
1047 light_green('quote 12 ') + ' will quote the tweet with ' + \
1048 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1049 'the quote will be canceled.\n'
1051 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1052 light_yellow('[id=12]') + '.\n'
1053 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1054 light_yellow('oops') + '" to tweet with ' + \
1055 light_yellow('[id=12]') + '.\n'
1057 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1058 light_yellow('[id=12]') + '.\n'
1060 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1061 light_yellow('[id=12]') + '.\n'
1063 light_green('del 12 ') + ' will delete tweet with ' + \
1064 light_yellow('[id=12]') + '.\n'
1065 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1066 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1067 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1068 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1072 def help_messages():
1079 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1080 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1081 light_green('inbox 7') + ' will show newest 7 messages.\n'
1082 usage
+= s
* 2 + light_green('sent') + ' will show sent messages. ' + \
1083 light_green('sent 7') + ' will show newest 7 messages.\n'
1084 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1085 magenta('@dtvd88') + '.\n'
1086 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1087 light_yellow('[message_id=5]') + '.\n'
1091 def help_friends_and_followers():
1093 Friends and Followers
1096 # Follower and following
1098 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1100 light_green('ls fl') + \
1101 ' will list all followers (people who are following you).\n'
1103 light_green('ls fr') + \
1104 ' will list all friends (people who you are following).\n'
1105 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1106 magenta('@dtvd88') + '.\n'
1107 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1108 magenta('@dtvd88') + '.\n'
1109 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1110 magenta('@dtvd88') + '.\n'
1111 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1112 magenta('@dtvd88') + '.\n'
1113 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1114 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1115 magenta('@dtvd88') + '.\n'
1116 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1117 magenta('@dtvd88') + '.\n'
1118 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1119 magenta('@dtvd88') + ' as a spam account.\n'
1130 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1131 usage
+= s
* 2 + light_green('list') + \
1132 ' will show all lists you are belong to.\n'
1133 usage
+= s
* 2 + light_green('list home') + \
1134 ' will show timeline of list. You will be asked for list\'s name\n'
1135 usage
+= s
* 2 + light_green('list all_mem') + \
1136 ' will show list\'s all members.\n'
1137 usage
+= s
* 2 + light_green('list all_sub') + \
1138 ' will show list\'s all subscribers.\n'
1139 usage
+= s
* 2 + light_green('list rm') + \
1140 ' will remove specific person from a list owned by you.' + \
1141 ' You will be asked for list\'s name and person\'s name.\n'
1152 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1153 usage
+= s
* 2 + light_green('switch public #AKB') + \
1154 ' will switch to public stream and follow "' + \
1155 light_yellow('AKB') + '" keyword.\n'
1156 usage
+= s
* 2 + light_green('switch mine') + \
1157 ' will switch to your personal stream.\n'
1158 usage
+= s
* 2 + light_green('switch mine -f ') + \
1159 ' will prompt to enter the filter.\n'
1160 usage
+= s
* 3 + light_yellow('Only nicks') + \
1161 ' filter will decide nicks will be INCLUDE ONLY.\n'
1162 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1163 ' filter will decide nicks will be EXCLUDE.\n'
1164 usage
+= s
* 2 + light_green('switch mine -d') + \
1165 ' will use the config\'s ONLY_LIST and IGNORE_LIST.\n'
1174 h
, w
= os
.popen('stty size', 'r').read().split()
1178 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1179 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1180 usage
+= s
+ 'You are ' + \
1181 light_yellow('already') + ' on your personal stream.\n'
1182 usage
+= s
+ 'Any update from Twitter will show up ' + \
1183 light_yellow('immediately') + '.\n'
1184 usage
+= s
+ 'In addtion, following commands are available right now:\n'
1186 # Twitter help section
1188 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1189 usage
+= s
* 2 + light_green('h discover') + \
1190 ' will show help for discover commands.\n'
1191 usage
+= s
* 2 + light_green('h tweets') + \
1192 ' will show help for tweets commands.\n'
1193 usage
+= s
* 2 + light_green('h messages') + \
1194 ' will show help for messages commands.\n'
1195 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1196 ' will show help for friends and followers commands.\n'
1197 usage
+= s
* 2 + light_green('h list') + \
1198 ' will show help for list commands.\n'
1199 usage
+= s
* 2 + light_green('h stream') + \
1200 ' will show help for stream commands.\n'
1204 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1205 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1206 'will be evaluate by Python interpreter.\n'
1207 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1208 ' for current month.\n'
1212 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1213 usage
+= s
* 2 + light_green('theme') + ' will list available theme.' + \
1214 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1215 ' theme immediately.\n'
1216 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1217 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1218 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1222 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1223 usage
+= s
+ 'Have fun and hang tight! \n'
1227 'discover' : help_discover
,
1228 'tweets' : help_tweets
,
1229 'messages' : help_messages
,
1230 'friends_and_followers' : help_friends_and_followers
,
1232 'stream' : help_stream
,
1235 d
[g
['stuff'].strip()]()
1252 os
.system('rm -rf rainbow.db')
1253 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
1259 Reset prefix of line
1262 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1265 printNicely(str(eval(g
['cmd'])))
1319 Listen to user's input
1324 ['public', 'mine'], # switch
1339 ['image'], # show image
1341 ['fl', 'fr'], # list
1354 ['home','all_mem','all_sub','rm'], # list
1356 g
['themes'] + ['current_as_default'], # theme
1357 ['discover','tweets','messages','friends_and_followers','list','stream'], # help
1362 init_interactive_shell(d
)
1367 line
= raw_input(g
['decorated_name'])
1371 cmd
= line
.split()[0]
1375 # Save cmd to global variable and call process
1377 g
['stuff'] = ' '.join(line
.split()[1:])
1380 printNicely(red('OMG something is wrong with Twitter right now.'))
1381 # Not redisplay prefix
1382 if cmd
in ['switch', 't', 'rt', 'rep']:
1388 def stream(domain
, args
, name
='Rainbow Stream'):
1395 c
['USER_DOMAIN']: name
,
1396 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
1397 c
['SITE_DOMAIN']: 'Site Stream',
1400 ascii_art(art_dict
[domain
])
1402 # These arguments are optional:
1404 timeout
=args
.timeout
,
1405 block
=not args
.no_block
,
1406 heartbeat_timeout
=args
.heartbeat_timeout
)
1410 if args
.track_keywords
:
1411 query_args
['track'] = args
.track_keywords
1414 stream
= TwitterStream(
1420 if domain
== c
['USER_DOMAIN']:
1421 tweet_iter
= stream
.user(**query_args
)
1422 elif domain
== c
['SITE_DOMAIN']:
1423 tweet_iter
= stream
.site(**query_args
)
1425 if args
.track_keywords
:
1426 tweet_iter
= stream
.statuses
.filter(**query_args
)
1428 tweet_iter
= stream
.statuses
.sample()
1430 # Iterate over the stream.
1431 for tweet
in tweet_iter
:
1433 printNicely("-- None --")
1434 elif tweet
is Timeout
:
1435 printNicely("-- Timeout --")
1436 elif tweet
is HeartbeatTimeout
:
1437 printNicely("-- Heartbeat Timeout --")
1438 elif tweet
is Hangup
:
1439 printNicely("-- Hangup --")
1440 elif tweet
.get('text'):
1443 iot
=args
.image_on_term
,
1444 keyword
=args
.track_keywords
,
1448 except TwitterHTTPError
:
1451 magenta("We have maximum connection problem with twitter'stream API right now :("))
1458 # Spawn stream process
1459 args
= parse_arguments()
1461 get_decorated_name()
1463 except TwitterHTTPError
:
1466 magenta("I'm afraid we have maximum connection problem with twitter right now :("))
1467 printNicely(magenta("Let's try again later."))
1469 os
.system('rm -rf rainbow.db')
1477 g
['original_name']))
1480 # Start listen process
1484 g
['stream_pid'] = p
.pid
1485 g
['iot'] = args
.image_on_term