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(BytesIO(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
)
510 u
for u
in tweet
['text'].split() if u
.startswith('http://')]
512 printNicely(light_magenta('No url here @.@!'))
514 for link
in link_ary
:
515 webbrowser
.open(link
)
517 printNicely(red('Sorry I can\'t open url in this tweet.'))
522 List friends for followers
524 t
= Twitter(auth
=authen())
527 name
= g
['stuff'].split()[1]
528 if name
.startswith('@'):
531 printNicely(red('A name should begin with a \'@\''))
532 raise Exception('Invalid name')
534 name
= g
['original_name']
535 # Get list followers or friends
537 target
= g
['stuff'].split()[0]
539 printNicely(red('Omg some syntax is wrong.'))
541 d
= {'fl': 'followers', 'fr': 'friends'}
545 while next_cursor
!= 0:
546 list = getattr(t
, d
[target
]).list(
550 include_entities
=False,
552 for u
in list['users']:
553 rel
[u
['name']] = '@' + u
['screen_name']
554 next_cursor
= list['next_cursor']
556 printNicely('All: ' + str(len(rel
)) + ' ' + d
[target
] + '.')
558 user
= ' ' + cycle_color(name
)
559 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
565 Inbox direct messages
567 t
= Twitter(auth
=authen())
568 num
= c
['MESSAGES_DISPLAY']
570 if g
['stuff'].isdigit():
573 # Max message per page is 20 so we have to loop
575 rel
= rel
+ t
.direct_messages(
578 include_entities
=False,
583 rel
= rel
+ t
.direct_messages(
586 include_entities
=False,
590 printNicely('Inbox: newest ' + str(len(rel
)) + ' messages.')
591 for m
in reversed(rel
):
600 t
= Twitter(auth
=authen())
601 num
= c
['MESSAGES_DISPLAY']
603 if g
['stuff'].isdigit():
604 num
= int(g
['stuff'])
606 # Max message per page is 20 so we have to loop
608 rel
= rel
+ t
.direct_messages
.sent(
611 include_entities
=False,
616 rel
= rel
+ t
.direct_messages
.sent(
619 include_entities
=False,
623 printNicely('Sent: newest ' + str(len(rel
)) + ' messages.')
624 for m
in reversed(rel
):
633 t
= Twitter(auth
=authen())
635 rid
= int(g
['stuff'].split()[0])
637 printNicely(red('Sorry I can\'t understand.'))
638 mid
= db
.rainbow_to_message_query(rid
)[0].message_id
639 t
.direct_messages
.destroy(id=mid
)
640 printNicely(green('Message deleted.'))
645 Show profile of a specific user
647 t
= Twitter(auth
=authen())
648 screen_name
= g
['stuff'].split()[0]
649 if screen_name
.startswith('@'):
652 screen_name
=screen_name
[1:],
653 include_entities
=False)
654 show_profile(user
, g
['iot'])
656 printNicely(red('Omg no user.'))
658 printNicely(red('A name should begin with a \'@\''))
665 t
= Twitter(auth
=authen())
666 screen_name
= g
['stuff'].split()[0]
667 if screen_name
.startswith('@'):
668 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
669 printNicely(green('You are following ' + screen_name
+ ' now!'))
671 printNicely(red('A name should begin with a \'@\''))
678 t
= Twitter(auth
=authen())
679 screen_name
= g
['stuff'].split()[0]
680 if screen_name
.startswith('@'):
681 t
.friendships
.destroy(
682 screen_name
=screen_name
[1:],
683 include_entities
=False)
684 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
686 printNicely(red('A name should begin with a \'@\''))
693 t
= Twitter(auth
=authen())
695 screen_name
= g
['stuff'].split()[0]
697 printNicely(red('A name should be specified. '))
699 if screen_name
.startswith('@'):
700 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
701 if isinstance(rel
, dict):
702 printNicely(green(screen_name
+ ' is muted.'))
704 printNicely(red(rel
))
706 printNicely(red('A name should begin with a \'@\''))
713 t
= Twitter(auth
=authen())
715 screen_name
= g
['stuff'].split()[0]
717 printNicely(red('A name should be specified. '))
719 if screen_name
.startswith('@'):
720 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
721 if isinstance(rel
, dict):
722 printNicely(green(screen_name
+ ' is unmuted.'))
724 printNicely(red(rel
))
726 printNicely(red('A name should begin with a \'@\''))
733 t
= Twitter(auth
=authen())
738 while next_cursor
!= 0:
739 list = t
.mutes
.users
.list(
740 screen_name
=g
['original_name'],
743 include_entities
=False,
745 for u
in list['users']:
746 rel
[u
['name']] = '@' + u
['screen_name']
747 next_cursor
= list['next_cursor']
749 printNicely('All: ' + str(len(rel
)) + ' people.')
751 user
= ' ' + cycle_color(name
)
752 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
760 t
= Twitter(auth
=authen())
761 screen_name
= g
['stuff'].split()[0]
762 if screen_name
.startswith('@'):
764 screen_name
=screen_name
[1:],
765 include_entities
=False,
767 printNicely(green('You blocked ' + screen_name
+ '.'))
769 printNicely(red('A name should begin with a \'@\''))
776 t
= Twitter(auth
=authen())
777 screen_name
= g
['stuff'].split()[0]
778 if screen_name
.startswith('@'):
780 screen_name
=screen_name
[1:],
781 include_entities
=False,
783 printNicely(green('Unblock ' + screen_name
+ ' success!'))
785 printNicely(red('A name should begin with a \'@\''))
790 Report a user as a spam account
792 t
= Twitter(auth
=authen())
793 screen_name
= g
['stuff'].split()[0]
794 if screen_name
.startswith('@'):
796 screen_name
=screen_name
[1:])
797 printNicely(green('You reported ' + screen_name
+ '.'))
799 printNicely(red('Sorry I can\'t understand.'))
806 rel
= t
.lists
.list(screen_name
=g
['original_name'])
810 printNicely(light_magenta('You belong to no lists :)'))
818 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
819 # Get list name and owner
821 owner
, slug
= list_name
.split('/')
822 if slug
.startswith('@'):
825 printNicely(light_magenta('Please follow "@owner/list_name" format.'))
827 res
= t
.lists
.statuses(
829 owner_screen_name
=owner
,
831 include_entities
=False)
842 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
843 # Get list name and owner
845 owner
, slug
= list_name
.split('/')
846 if slug
.startswith('@'):
849 printNicely(light_magenta('Please follow "@owner/list_name" format.'))
854 while next_cursor
!= 0:
857 owner_screen_name
=owner
,
859 include_entities
=False)
861 rel
[u
['name']] = '@' + u
['screen_name']
862 next_cursor
= m
['next_cursor']
863 printNicely('All: ' + str(len(rel
)) + ' members.')
865 user
= ' ' + cycle_color(name
)
866 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
870 def list_subscribers(t
):
875 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
876 # Get list name and owner
878 owner
, slug
= list_name
.split('/')
879 if slug
.startswith('@'):
882 printNicely(light_magenta('Please follow "@owner/list_name" format.'))
887 while next_cursor
!= 0:
888 m
= t
.lists
.subscribers(
890 owner_screen_name
=owner
,
892 include_entities
=False)
894 rel
[u
['name']] = '@' + u
['screen_name']
895 next_cursor
= m
['next_cursor']
896 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
898 user
= ' ' + cycle_color(name
)
899 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
905 Add specific user to a list
908 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
909 # Get list name and owner
911 owner
, slug
= list_name
.split('/')
912 if slug
.startswith('@'):
915 printNicely(light_magenta('Please follow "@owner/list_name" format.'))
918 user_name
= raw_input(light_magenta('Give me name of the newbie: '))
919 if user_name
.startswith('@'):
920 user_name
= user_name
[1:]
922 t
.lists
.members
.create(
924 owner_screen_name
=owner
,
925 screen_name
=user_name
)
926 printNicely(light_green('Added.'))
928 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
933 Remove specific user from a list
936 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
937 # Get list name and owner
939 owner
, slug
= list_name
.split('/')
940 if slug
.startswith('@'):
943 printNicely(light_magenta('Please follow "@owner/list_name" format.'))
946 user_name
= raw_input(light_magenta('Give me name of the unlucky one: '))
947 if user_name
.startswith('@'):
948 user_name
= user_name
[1:]
950 t
.lists
.members
.destroy(
952 owner_screen_name
=owner
,
953 screen_name
=user_name
)
954 printNicely(light_green('Gone.'))
956 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
959 def list_subscribe(t
):
964 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
965 # Get list name and owner
967 owner
, slug
= list_name
.split('/')
968 if slug
.startswith('@'):
971 printNicely(light_magenta('Please follow "@owner/list_name" format.'))
975 t
.lists
.subscribers
.create(
977 owner_screen_name
=owner
)
978 printNicely(light_green('Done.'))
981 light_magenta('I\'m sorry you can not subscribe to this list.'))
984 def list_unsubscribe(t
):
989 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
990 # Get list name and owner
992 owner
, slug
= list_name
.split('/')
993 if slug
.startswith('@'):
996 printNicely(light_magenta('Please follow "@owner/list_name" format.'))
1000 t
.lists
.subscribers
.destroy(
1002 owner_screen_name
=owner
)
1003 printNicely(light_green('Done.'))
1006 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
1015 while next_cursor
!= 0:
1016 res
= t
.lists
.ownerships(
1017 screen_name
=g
['original_name'],
1020 next_cursor
= res
['next_cursor']
1024 printNicely(light_magenta('You own no lists :)'))
1031 name
= raw_input(light_magenta('New list\'s name: '))
1032 mode
= raw_input(light_magenta('New list\'s mode (public/private): '))
1033 description
= raw_input(light_magenta('New list\'s description: '))
1038 description
=description
)
1039 printNicely(light_green(name
+ ' list is created.'))
1041 printNicely(red('Oops something is wrong with Twitter :('))
1048 slug
= raw_input(light_magenta('Your list that you want to update: '))
1049 name
= raw_input(light_magenta('Update name (leave blank to unchange): '))
1050 mode
= raw_input(light_magenta('Update mode (public/private): '))
1051 description
= raw_input(light_magenta('Update description: '))
1055 slug
='-'.join(slug
.split()),
1056 owner_screen_name
=g
['original_name'],
1059 description
=description
)
1063 owner_screen_name
=g
['original_name'],
1065 description
=description
)
1066 printNicely(light_green(slug
+ ' list is updated.'))
1068 printNicely(red('Oops something is wrong with Twitter :('))
1075 slug
= raw_input(light_magenta('Your list that you want to update: '))
1078 slug
='-'.join(slug
.split()),
1079 owner_screen_name
=g
['original_name'])
1080 printNicely(light_green(slug
+ ' list is deleted.'))
1082 printNicely(red('Oops something is wrong with Twitter :('))
1089 t
= Twitter(auth
=authen())
1090 # List all lists or base on action
1092 g
['list_action'] = g
['stuff'].split()[0]
1099 'all_mem': list_members
,
1100 'all_sub': list_subscribers
,
1103 'sub': list_subscribe
,
1104 'unsub': list_unsubscribe
,
1107 'update': list_update
,
1111 return action_ary
[g
['list_action']](t
)
1113 printNicely(red('Sorry I can\'t understand.'))
1118 Unix's command `cal`
1121 rel
= os
.popen('cal').read().split('\n')
1124 show_calendar(month
, date
, rel
)
1129 List and change theme
1133 for theme
in g
['themes']:
1135 # Detect custom config
1136 if theme
== 'custom':
1137 line
+= light_magenta('custom')
1138 custom_path
= os
.environ
.get(
1140 os
.environ
.get('USERPROFILE',
1141 '')) + os
.sep
+ '.rainbow_config.json'
1142 if not os
.path
.exists(custom_path
):
1143 line
+= light_magenta(
1144 ' (create your own config file at ~/.rainbow_config.json)')
1146 line
+= light_magenta(' (loaded)')
1148 line
+= light_magenta(theme
)
1149 if c
['theme'] == theme
:
1150 line
= ' ' * 2 + light_yellow('* ') + line
1152 line
= ' ' * 4 + line
1154 elif g
['stuff'] == 'current_as_default':
1156 path
= os
.path
.dirname(__file__
) + '/colorset/init'
1160 os
.system('chmod 777 ' + path
)
1161 printNicely(light_green('Okay it will be applied from next time :)'))
1166 if g
['stuff'] != 'custom':
1167 new_config
= os
.path
.dirname(
1168 __file__
) + '/colorset/' + g
['stuff'] + '.json'
1170 new_config
= os
.environ
.get(
1171 'HOME', os
.environ
.get(
1173 '')) + os
.sep
+ '.rainbow_config.json'
1174 new_config
= load_config(new_config
)
1176 for nc
in new_config
:
1177 c
[nc
] = new_config
[nc
]
1178 # Update db and reset colors
1179 db
.theme_update(g
['stuff'])
1180 c
['theme'] = g
['stuff']
1182 g
['decorated_name'] = color_func(
1183 c
['DECORATED_NAME'])(
1184 '[@' + g
['original_name'] + ']: ')
1185 printNicely(green('Theme changed.'))
1187 if g
['stuff'] == 'custom':
1188 printNicely(red('~/.rainbow_config.json is not exists!'))
1190 printNicely(red('No such theme exists.'))
1193 def help_discover():
1198 # Discover the world
1200 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1201 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1202 'You can try ' + light_green('trend US') + ' or ' + \
1203 light_green('trend JP Tokyo') + '.\n'
1204 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1205 light_green('home 7') + ' will show 7 tweets.\n'
1206 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1207 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1208 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1209 magenta('@mdo') + '.\n'
1210 usage
+= s
* 2 + light_green('view @mdo') + \
1211 ' will show ' + magenta('@mdo') + '\'s home.\n'
1212 usage
+= s
* 2 + light_green('s #AKB48') + ' will search for "' + \
1213 light_yellow('AKB48') + '" and return 5 newest tweet.\n'
1224 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1225 usage
+= s
* 2 + light_green('t oops ') + \
1226 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1228 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1229 light_yellow('[id=12]') + '.\n'
1231 light_green('quote 12 ') + ' will quote the tweet with ' + \
1232 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1233 'the quote will be canceled.\n'
1235 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1236 light_yellow('[id=12]') + '.\n'
1237 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1238 light_yellow('oops') + '" to tweet with ' + \
1239 light_yellow('[id=12]') + '.\n'
1241 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1242 light_yellow('[id=12]') + '.\n'
1244 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1245 light_yellow('[id=12]') + '.\n'
1247 light_green('del 12 ') + ' will delete tweet with ' + \
1248 light_yellow('[id=12]') + '.\n'
1249 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1250 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1251 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1252 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1256 def help_messages():
1263 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1264 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1265 light_green('inbox 7') + ' will show newest 7 messages.\n'
1266 usage
+= s
* 2 + light_green('sent') + ' will show sent messages. ' + \
1267 light_green('sent 7') + ' will show newest 7 messages.\n'
1268 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1269 magenta('@dtvd88') + '.\n'
1270 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1271 light_yellow('[message_id=5]') + '.\n'
1275 def help_friends_and_followers():
1277 Friends and Followers
1280 # Follower and following
1282 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1284 light_green('ls fl') + \
1285 ' will list all followers (people who are following you).\n'
1287 light_green('ls fr') + \
1288 ' will list all friends (people who you are following).\n'
1289 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1290 magenta('@dtvd88') + '.\n'
1291 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1292 magenta('@dtvd88') + '.\n'
1293 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1294 magenta('@dtvd88') + '.\n'
1295 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1296 magenta('@dtvd88') + '.\n'
1297 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1298 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1299 magenta('@dtvd88') + '.\n'
1300 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1301 magenta('@dtvd88') + '.\n'
1302 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1303 magenta('@dtvd88') + ' as a spam account.\n'
1314 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1315 usage
+= s
* 2 + light_green('list') + \
1316 ' will show all lists you are belong to.\n'
1317 usage
+= s
* 2 + light_green('list home') + \
1318 ' will show timeline of list. You will be asked for list\'s name.\n'
1319 usage
+= s
* 2 + light_green('list all_mem') + \
1320 ' will show list\'s all members.\n'
1321 usage
+= s
* 2 + light_green('list all_sub') + \
1322 ' will show list\'s all subscribers.\n'
1323 usage
+= s
* 2 + light_green('list add') + \
1324 ' will add specific person to a list owned by you.' + \
1325 ' You will be asked for list\'s name and person\'s name.\n'
1326 usage
+= s
* 2 + light_green('list rm') + \
1327 ' will remove specific person from a list owned by you.' + \
1328 ' You will be asked for list\'s name and person\'s name.\n'
1329 usage
+= s
* 2 + light_green('list sub') + \
1330 ' will subscribe you to a specific list.\n'
1331 usage
+= s
* 2 + light_green('list unsub') + \
1332 ' will unsubscribe you from a specific list.\n'
1333 usage
+= s
* 2 + light_green('list own') + \
1334 ' will show all list owned by you.\n'
1335 usage
+= s
* 2 + light_green('list new') + \
1336 ' will create a new list.\n'
1337 usage
+= s
* 2 + light_green('list update') + \
1338 ' will update a list owned by you.\n'
1339 usage
+= s
* 2 + light_green('list del') + \
1340 ' will delete a list owned by you.\n'
1351 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1352 usage
+= s
* 2 + light_green('switch public #AKB') + \
1353 ' will switch to public stream and follow "' + \
1354 light_yellow('AKB') + '" keyword.\n'
1355 usage
+= s
* 2 + light_green('switch mine') + \
1356 ' will switch to your personal stream.\n'
1357 usage
+= s
* 2 + light_green('switch mine -f ') + \
1358 ' will prompt to enter the filter.\n'
1359 usage
+= s
* 3 + light_yellow('Only nicks') + \
1360 ' filter will decide nicks will be INCLUDE ONLY.\n'
1361 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1362 ' filter will decide nicks will be EXCLUDE.\n'
1363 usage
+= s
* 2 + light_green('switch mine -d') + \
1364 ' will use the config\'s ONLY_LIST and IGNORE_LIST.\n'
1373 h
, w
= os
.popen('stty size', 'r').read().split()
1377 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1378 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1379 usage
+= s
+ 'You are ' + \
1380 light_yellow('already') + ' on your personal stream.\n'
1381 usage
+= s
+ 'Any update from Twitter will show up ' + \
1382 light_yellow('immediately') + '.\n'
1383 usage
+= s
+ 'In addtion, following commands are available right now:\n'
1385 # Twitter help section
1387 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1388 usage
+= s
* 2 + light_green('h discover') + \
1389 ' will show help for discover commands.\n'
1390 usage
+= s
* 2 + light_green('h tweets') + \
1391 ' will show help for tweets commands.\n'
1392 usage
+= s
* 2 + light_green('h messages') + \
1393 ' will show help for messages commands.\n'
1394 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1395 ' will show help for friends and followers commands.\n'
1396 usage
+= s
* 2 + light_green('h list') + \
1397 ' will show help for list commands.\n'
1398 usage
+= s
* 2 + light_green('h stream') + \
1399 ' will show help for stream commands.\n'
1403 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1404 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1405 'will be evaluate by Python interpreter.\n'
1406 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1407 ' for current month.\n'
1411 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1412 usage
+= s
* 2 + light_green('theme') + ' will list available theme.' + \
1413 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1414 ' theme immediately.\n'
1415 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1416 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1417 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1421 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1422 usage
+= s
+ 'Have fun and hang tight! \n'
1426 'discover': help_discover
,
1427 'tweets': help_tweets
,
1428 'messages': help_messages
,
1429 'friends_and_followers': help_friends_and_followers
,
1431 'stream': help_stream
,
1434 d
[g
['stuff'].strip()]()
1451 os
.system('rm -rf rainbow.db')
1452 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
1458 Reset prefix of line
1461 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1464 printNicely(str(eval(g
['cmd'])))
1518 Listen to user's input
1523 ['public', 'mine'], # switch
1538 ['image'], # show image
1540 ['fl', 'fr'], # list
1567 g
['themes'] + ['current_as_default'], # theme
1572 'friends_and_followers',
1580 init_interactive_shell(d
)
1585 line
= raw_input(g
['decorated_name'])
1589 cmd
= line
.split()[0]
1593 # Save cmd to global variable and call process
1595 g
['stuff'] = ' '.join(line
.split()[1:])
1598 printNicely(red('OMG something is wrong with Twitter right now.'))
1599 # Not redisplay prefix
1600 if cmd
in ['switch', 't', 'rt', 'rep']:
1606 def stream(domain
, args
, name
='Rainbow Stream'):
1613 c
['USER_DOMAIN']: name
,
1614 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
1615 c
['SITE_DOMAIN']: 'Site Stream',
1618 ascii_art(art_dict
[domain
])
1620 # These arguments are optional:
1622 timeout
=args
.timeout
,
1623 block
=not args
.no_block
,
1624 heartbeat_timeout
=args
.heartbeat_timeout
)
1628 if args
.track_keywords
:
1629 query_args
['track'] = args
.track_keywords
1632 stream
= TwitterStream(
1638 if domain
== c
['USER_DOMAIN']:
1639 tweet_iter
= stream
.user(**query_args
)
1640 elif domain
== c
['SITE_DOMAIN']:
1641 tweet_iter
= stream
.site(**query_args
)
1643 if args
.track_keywords
:
1644 tweet_iter
= stream
.statuses
.filter(**query_args
)
1646 tweet_iter
= stream
.statuses
.sample()
1648 # Iterate over the stream.
1649 for tweet
in tweet_iter
:
1651 printNicely("-- None --")
1652 elif tweet
is Timeout
:
1653 printNicely("-- Timeout --")
1654 elif tweet
is HeartbeatTimeout
:
1655 printNicely("-- Heartbeat Timeout --")
1656 elif tweet
is Hangup
:
1657 printNicely("-- Hangup --")
1658 elif tweet
.get('text'):
1661 iot
=args
.image_on_term
,
1662 keyword
=args
.track_keywords
,
1666 except TwitterHTTPError
:
1669 magenta("We have maximum connection problem with twitter'stream API right now :("))
1676 # Spawn stream process
1677 args
= parse_arguments()
1679 get_decorated_name()
1681 except TwitterHTTPError
:
1684 magenta("Something wrong with Twitter Oauth right now :("))
1686 magenta("Please delete ~/.rainbow_oauth and try again."))
1688 os
.system('rm -rf rainbow.db')
1696 g
['original_name']))
1699 # Start listen process
1703 g
['stream_pid'] = p
.pid
1704 g
['iot'] = args
.image_on_term