2 Colorful user's timeline stream
4 from multiprocessing
import Process
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 *
28 from .c_image
import *
29 from .py3patch
import *
74 def parse_arguments():
78 parser
= argparse
.ArgumentParser(description
=__doc__
or "")
82 help='Timeout for the stream (seconds).')
85 '--heartbeat-timeout',
86 help='Set heartbeat timeout.',
92 help='Set stream to non-blocking.')
96 help='Search the stream for specific text.')
100 help='Filter specific screen_name.')
104 help='Ignore specific screen_name.')
109 help='Display all image on terminal.')
110 return parser
.parse_args()
115 Authenticate with Twitter OAuth
117 # When using rainbow stream you must authorize.
118 twitter_credential
= os
.environ
.get(
122 '')) + os
.sep
+ '.rainbow_oauth'
123 if not os
.path
.exists(twitter_credential
):
124 oauth_dance("Rainbow Stream",
128 oauth_token
, oauth_token_secret
= read_token_file(twitter_credential
)
136 def get_decorated_name():
138 Beginning of every line
140 t
= Twitter(auth
=authen())
141 name
= '@' + t
.account
.verify_credentials()['screen_name']
142 g
['original_name'] = name
[1:]
143 g
['decorated_name'] = color_func(c
['DECORATED_NAME'])('[' + name
+ ']: ')
144 g
['ascii_art'] = True
146 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
147 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']:
1134 line
= light_magenta(theme
)
1135 if c
['THEME'] == theme
:
1136 line
= ' ' * 2 + light_yellow('* ') + line
1138 line
= ' ' * 4 + line
1140 elif g
['stuff'] == 'current_as_default':
1142 def fixup(adict
, k
, v
):
1143 for key
in adict
.keys():
1146 elif type(adict
[key
]) is dict:
1147 fixup(adict
[key
], k
, v
)
1149 path
= os
.environ
.get(
1153 '')) + os
.sep
+ '.rainbow_config.json'
1154 data
= load_config(rainbow_config
)
1155 fixup(data
, 'THEME', c
['THEME'])
1157 with
open(path
, 'w') as out
:
1158 json
.dump(data
, out
, indent
= 4)
1159 os
.system('chmod 777 ' + path
)
1160 printNicely(light_green('Okay it will be applied from next time :)'))
1165 if g
['stuff'] != 'custom':
1166 new_config
= os
.path
.dirname(
1167 __file__
) + '/colorset/' + g
['stuff'] + '.json'
1169 new_config
= os
.environ
.get(
1170 'HOME', os
.environ
.get(
1172 '')) + os
.sep
+ '.rainbow_config.json'
1173 new_config
= load_config(new_config
)
1175 for nc
in new_config
:
1176 c
[nc
] = new_config
[nc
]
1177 # Update db and reset colors
1178 db
.theme_update(g
['stuff'])
1179 c
['THEME'] = g
['stuff']
1181 g
['decorated_name'] = color_func(
1182 c
['DECORATED_NAME'])(
1183 '[@' + g
['original_name'] + ']: ')
1184 printNicely(green('Theme changed.'))
1186 printNicely(red('No such theme exists.'))
1189 def help_discover():
1194 # Discover the world
1196 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1197 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1198 'You can try ' + light_green('trend US') + ' or ' + \
1199 light_green('trend JP Tokyo') + '.\n'
1200 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1201 light_green('home 7') + ' will show 7 tweets.\n'
1202 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1203 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1204 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1205 magenta('@mdo') + '.\n'
1206 usage
+= s
* 2 + light_green('view @mdo') + \
1207 ' will show ' + magenta('@mdo') + '\'s home.\n'
1208 usage
+= s
* 2 + light_green('s #AKB48') + ' will search for "' + \
1209 light_yellow('AKB48') + '" and return 5 newest tweet.\n'
1220 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1221 usage
+= s
* 2 + light_green('t oops ') + \
1222 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1224 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1225 light_yellow('[id=12]') + '.\n'
1227 light_green('quote 12 ') + ' will quote the tweet with ' + \
1228 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1229 'the quote will be canceled.\n'
1231 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1232 light_yellow('[id=12]') + '.\n'
1233 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1234 light_yellow('oops') + '" to tweet with ' + \
1235 light_yellow('[id=12]') + '.\n'
1237 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1238 light_yellow('[id=12]') + '.\n'
1240 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1241 light_yellow('[id=12]') + '.\n'
1243 light_green('del 12 ') + ' will delete tweet with ' + \
1244 light_yellow('[id=12]') + '.\n'
1245 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1246 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1247 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1248 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1252 def help_messages():
1259 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1260 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1261 light_green('inbox 7') + ' will show newest 7 messages.\n'
1262 usage
+= s
* 2 + light_green('sent') + ' will show sent messages. ' + \
1263 light_green('sent 7') + ' will show newest 7 messages.\n'
1264 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1265 magenta('@dtvd88') + '.\n'
1266 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1267 light_yellow('[message_id=5]') + '.\n'
1271 def help_friends_and_followers():
1273 Friends and Followers
1276 # Follower and following
1278 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1280 light_green('ls fl') + \
1281 ' will list all followers (people who are following you).\n'
1283 light_green('ls fr') + \
1284 ' will list all friends (people who you are following).\n'
1285 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1286 magenta('@dtvd88') + '.\n'
1287 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1288 magenta('@dtvd88') + '.\n'
1289 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1290 magenta('@dtvd88') + '.\n'
1291 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1292 magenta('@dtvd88') + '.\n'
1293 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1294 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1295 magenta('@dtvd88') + '.\n'
1296 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1297 magenta('@dtvd88') + '.\n'
1298 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1299 magenta('@dtvd88') + ' as a spam account.\n'
1310 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1311 usage
+= s
* 2 + light_green('list') + \
1312 ' will show all lists you are belong to.\n'
1313 usage
+= s
* 2 + light_green('list home') + \
1314 ' will show timeline of list. You will be asked for list\'s name.\n'
1315 usage
+= s
* 2 + light_green('list all_mem') + \
1316 ' will show list\'s all members.\n'
1317 usage
+= s
* 2 + light_green('list all_sub') + \
1318 ' will show list\'s all subscribers.\n'
1319 usage
+= s
* 2 + light_green('list add') + \
1320 ' will add specific person to a list owned by you.' + \
1321 ' You will be asked for list\'s name and person\'s name.\n'
1322 usage
+= s
* 2 + light_green('list rm') + \
1323 ' will remove specific person from a list owned by you.' + \
1324 ' You will be asked for list\'s name and person\'s name.\n'
1325 usage
+= s
* 2 + light_green('list sub') + \
1326 ' will subscribe you to a specific list.\n'
1327 usage
+= s
* 2 + light_green('list unsub') + \
1328 ' will unsubscribe you from a specific list.\n'
1329 usage
+= s
* 2 + light_green('list own') + \
1330 ' will show all list owned by you.\n'
1331 usage
+= s
* 2 + light_green('list new') + \
1332 ' will create a new list.\n'
1333 usage
+= s
* 2 + light_green('list update') + \
1334 ' will update a list owned by you.\n'
1335 usage
+= s
* 2 + light_green('list del') + \
1336 ' will delete a list owned by you.\n'
1347 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1348 usage
+= s
* 2 + light_green('switch public #AKB') + \
1349 ' will switch to public stream and follow "' + \
1350 light_yellow('AKB') + '" keyword.\n'
1351 usage
+= s
* 2 + light_green('switch mine') + \
1352 ' will switch to your personal stream.\n'
1353 usage
+= s
* 2 + light_green('switch mine -f ') + \
1354 ' will prompt to enter the filter.\n'
1355 usage
+= s
* 3 + light_yellow('Only nicks') + \
1356 ' filter will decide nicks will be INCLUDE ONLY.\n'
1357 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1358 ' filter will decide nicks will be EXCLUDE.\n'
1359 usage
+= s
* 2 + light_green('switch mine -d') + \
1360 ' will use the config\'s ONLY_LIST and IGNORE_LIST.\n'
1369 h
, w
= os
.popen('stty size', 'r').read().split()
1373 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1374 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1375 usage
+= s
+ 'You are ' + \
1376 light_yellow('already') + ' on your personal stream.\n'
1377 usage
+= s
+ 'Any update from Twitter will show up ' + \
1378 light_yellow('immediately') + '.\n'
1379 usage
+= s
+ 'In addtion, following commands are available right now:\n'
1381 # Twitter help section
1383 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1384 usage
+= s
* 2 + light_green('h discover') + \
1385 ' will show help for discover commands.\n'
1386 usage
+= s
* 2 + light_green('h tweets') + \
1387 ' will show help for tweets commands.\n'
1388 usage
+= s
* 2 + light_green('h messages') + \
1389 ' will show help for messages commands.\n'
1390 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1391 ' will show help for friends and followers commands.\n'
1392 usage
+= s
* 2 + light_green('h list') + \
1393 ' will show help for list commands.\n'
1394 usage
+= s
* 2 + light_green('h stream') + \
1395 ' will show help for stream commands.\n'
1399 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1400 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1401 'will be evaluate by Python interpreter.\n'
1402 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1403 ' for current month.\n'
1407 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1408 usage
+= s
* 2 + light_green('theme') + ' will list available theme.' + \
1409 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1410 ' theme immediately.\n'
1411 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1412 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1413 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1417 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1418 usage
+= s
+ 'Have fun and hang tight! \n'
1422 'discover': help_discover
,
1423 'tweets': help_tweets
,
1424 'messages': help_messages
,
1425 'friends_and_followers': help_friends_and_followers
,
1427 'stream': help_stream
,
1430 d
[g
['stuff'].strip()]()
1447 os
.system('rm -rf rainbow.db')
1448 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
1454 Reset prefix of line
1457 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1460 printNicely(str(eval(g
['cmd'])))
1514 Listen to user's input
1519 ['public', 'mine'], # switch
1534 ['image'], # show image
1536 ['fl', 'fr'], # list
1563 g
['themes'] + ['current_as_default'], # theme
1568 'friends_and_followers',
1576 init_interactive_shell(d
)
1581 line
= raw_input(g
['decorated_name'])
1585 cmd
= line
.split()[0]
1589 # Save cmd to global variable and call process
1591 g
['stuff'] = ' '.join(line
.split()[1:])
1594 printNicely(red('OMG something is wrong with Twitter right now.'))
1595 # Not redisplay prefix
1596 if cmd
in ['switch', 't', 'rt', 'rep']:
1602 def stream(domain
, args
, name
='Rainbow Stream'):
1609 c
['USER_DOMAIN']: name
,
1610 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
1611 c
['SITE_DOMAIN']: name
,
1614 ascii_art(art_dict
[domain
])
1616 # These arguments are optional:
1618 timeout
=args
.timeout
,
1619 block
=not args
.no_block
,
1620 heartbeat_timeout
=args
.heartbeat_timeout
)
1624 if args
.track_keywords
:
1625 query_args
['track'] = args
.track_keywords
1628 stream
= TwitterStream(
1634 if domain
== c
['USER_DOMAIN']:
1635 tweet_iter
= stream
.user(**query_args
)
1636 elif domain
== c
['SITE_DOMAIN']:
1637 tweet_iter
= stream
.site(**query_args
)
1639 if args
.track_keywords
:
1640 tweet_iter
= stream
.statuses
.filter(**query_args
)
1642 tweet_iter
= stream
.statuses
.sample()
1644 # Iterate over the stream.
1645 for tweet
in tweet_iter
:
1647 printNicely("-- None --")
1648 elif tweet
is Timeout
:
1649 printNicely("-- Timeout --")
1650 elif tweet
is HeartbeatTimeout
:
1651 printNicely("-- Heartbeat Timeout --")
1652 elif tweet
is Hangup
:
1653 printNicely("-- Hangup --")
1654 elif tweet
.get('text'):
1657 iot
=args
.image_on_term
,
1658 keyword
=args
.track_keywords
,
1662 except TwitterHTTPError
:
1665 magenta("We have maximum connection problem with twitter'stream API right now :("))
1672 # Spawn stream process
1673 args
= parse_arguments()
1675 get_decorated_name()
1677 except TwitterHTTPError
:
1680 magenta("Something wrong with Twitter Oauth right now :("))
1682 magenta("Please delete ~/.rainbow_oauth and try again."))
1684 os
.system('rm -rf rainbow.db')
1692 g
['original_name']))
1695 # Start listen process
1699 g
['stream_pid'] = p
.pid
1700 g
['iot'] = args
.image_on_term