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
+ ']: ')
145 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
146 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
)))
210 printNicely(red('Sorry I can\'t understand.'))
217 t
= Twitter(auth
=authen())
218 # Get country and town
220 country
= g
['stuff'].split()[0]
224 town
= g
['stuff'].split()[1]
228 avail
= t
.trends
.available()
231 trends
= t
.trends
.place(_id
=1)[0]['trends']
234 for location
in avail
:
235 # Search for country and Town
237 if location
['countryCode'] == country \
238 and location
['placeType']['name'] == 'Town' \
239 and location
['name'] == town
:
240 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
242 # Search for country only
244 if location
['countryCode'] == country \
245 and location
['placeType']['name'] == 'Country':
246 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
254 t
= Twitter(auth
=authen())
255 num
= c
['HOME_TWEET_NUM']
256 if g
['stuff'].isdigit():
257 num
= int(g
['stuff'])
258 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
259 draw(t
=tweet
, iot
=g
['iot'])
267 t
= Twitter(auth
=authen())
268 user
= g
['stuff'].split()[0]
271 num
= int(g
['stuff'].split()[1])
273 num
= c
['HOME_TWEET_NUM']
274 for tweet
in reversed(t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
275 draw(t
=tweet
, iot
=g
['iot'])
278 printNicely(red('A name should begin with a \'@\''))
285 t
= Twitter(auth
=authen())
286 num
= c
['HOME_TWEET_NUM']
287 if g
['stuff'].isdigit():
288 num
= int(g
['stuff'])
289 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
290 draw(t
=tweet
, iot
=g
['iot'])
298 t
= Twitter(auth
=authen())
299 t
.statuses
.update(status
=g
['stuff'])
306 t
= Twitter(auth
=authen())
308 id = int(g
['stuff'].split()[0])
310 printNicely(red('Sorry I can\'t understand.'))
312 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
313 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
320 t
= Twitter(auth
=authen())
322 id = int(g
['stuff'].split()[0])
324 printNicely(red('Sorry I can\'t understand.'))
326 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
327 tweet
= t
.statuses
.show(id=tid
)
328 screen_name
= tweet
['user']['screen_name']
330 quote
= '\"@' + screen_name
+ ': ' + text
+ '\"'
331 quote
= quote
.encode('utf8')
332 notice
= light_magenta('Compose mode ')
333 notice
+= light_yellow('(Enter nothing will cancel the quote)')
334 notice
+= light_magenta(':')
336 extra
= raw_input(quote
)
338 t
.statuses
.update(status
=quote
+ extra
)
340 printNicely(light_magenta('No text added.'))
347 t
= Twitter(auth
=authen())
350 id = int(g
['stuff'].split()[0])
352 printNicely(red('Sorry I can\'t understand.'))
354 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
355 # Get display num if exist
357 num
= int(g
['stuff'].split()[1])
359 num
= c
['RETWEETS_SHOW_NUM']
360 # Get result and display
361 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
363 printNicely(magenta('This tweet has no retweet.'))
365 for tweet
in reversed(rt_ary
):
366 draw(t
=tweet
, iot
=g
['iot'])
374 t
= Twitter(auth
=authen())
376 id = int(g
['stuff'].split()[0])
378 printNicely(red('Sorry I can\'t understand.'))
380 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
381 t
.favorites
.create(_id
=tid
, include_entities
=False)
382 printNicely(green('Favorited.'))
383 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
391 t
= Twitter(auth
=authen())
393 id = int(g
['stuff'].split()[0])
395 printNicely(red('Sorry I can\'t understand.'))
397 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
398 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
399 status
= ' '.join(g
['stuff'].split()[1:])
400 status
= '@' + user
+ ' ' + status
.decode('utf-8')
401 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
408 t
= Twitter(auth
=authen())
410 rid
= int(g
['stuff'].split()[0])
412 printNicely(red('Sorry I can\'t understand.'))
414 tid
= db
.rainbow_to_tweet_query(rid
)[0].tweet_id
415 t
.statuses
.destroy(id=tid
)
416 printNicely(green('Okay it\'s gone.'))
423 t
= Twitter(auth
=authen())
425 id = int(g
['stuff'].split()[0])
427 printNicely(red('Sorry I can\'t understand.'))
429 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
430 t
.favorites
.destroy(_id
=tid
)
431 printNicely(green('Okay it\'s unfavorited.'))
432 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
440 t
= Twitter(auth
=authen())
441 if g
['stuff'].startswith('#'):
442 rel
= t
.search
.tweets(q
=g
['stuff'])['statuses']
444 printNicely('Newest tweets:')
445 for i
in reversed(xrange(c
['SEARCH_MAX_RECORD'])):
448 keyword
=g
['stuff'].strip()[1:])
451 printNicely(magenta('I\'m afraid there is no result'))
453 printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
458 Send a direct message
460 t
= Twitter(auth
=authen())
461 user
= g
['stuff'].split()[0]
462 if user
[0].startswith('@'):
464 content
= g
['stuff'].split()[1]
466 printNicely(red('Sorry I can\'t understand.'))
467 t
.direct_messages
.new(
468 screen_name
=user
[1:],
471 printNicely(green('Message sent.'))
473 printNicely(red('A name should begin with a \'@\''))
480 t
= Twitter(auth
=authen())
482 target
= g
['stuff'].split()[0]
483 if target
!= 'image':
485 id = int(g
['stuff'].split()[1])
486 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
487 tweet
= t
.statuses
.show(id=tid
)
488 media
= tweet
['entities']['media']
490 res
= requests
.get(m
['media_url'])
491 img
= Image
.open(BytesIO(res
.content
))
494 printNicely(red('Sorry I can\'t show this image.'))
501 t
= Twitter(auth
=authen())
503 if not g
['stuff'].isdigit():
505 tid
= db
.rainbow_to_tweet_query(g
['stuff'])[0].tweet_id
506 tweet
= t
.statuses
.show(id=tid
)
508 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.'))
805 list_name
= raw_input(light_magenta('Give me the list\'s name: '))
806 # Get list name and owner
808 owner
, slug
= list_name
.split('/')
809 if slug
.startswith('@'):
813 printNicely(light_magenta('List name should follow "@owner/list_name" format.'))
814 raise Exception('Wrong list name')
821 rel
= t
.lists
.list(screen_name
=g
['original_name'])
825 printNicely(light_magenta('You belong to no lists :)'))
832 owner
, slug
= get_slug()
833 res
= t
.lists
.statuses(
835 owner_screen_name
=owner
,
837 include_entities
=False)
847 owner
, slug
= get_slug()
851 while next_cursor
!= 0:
854 owner_screen_name
=owner
,
856 include_entities
=False)
858 rel
[u
['name']] = '@' + u
['screen_name']
859 next_cursor
= m
['next_cursor']
860 printNicely('All: ' + str(len(rel
)) + ' members.')
862 user
= ' ' + cycle_color(name
)
863 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
867 def list_subscribers(t
):
871 owner
, slug
= get_slug()
875 while next_cursor
!= 0:
876 m
= t
.lists
.subscribers(
878 owner_screen_name
=owner
,
880 include_entities
=False)
882 rel
[u
['name']] = '@' + u
['screen_name']
883 next_cursor
= m
['next_cursor']
884 printNicely('All: ' + str(len(rel
)) + ' subscribers.')
886 user
= ' ' + cycle_color(name
)
887 user
+= color_func(c
['TWEET']['nick'])(' ' + rel
[name
] + ' ')
893 Add specific user to a list
895 owner
, slug
= get_slug()
897 user_name
= raw_input(light_magenta('Give me name of the newbie: '))
898 if user_name
.startswith('@'):
899 user_name
= user_name
[1:]
901 t
.lists
.members
.create(
903 owner_screen_name
=owner
,
904 screen_name
=user_name
)
905 printNicely(light_green('Added.'))
907 printNicely(light_magenta('I\'m sorry we can not add him/her.'))
912 Remove specific user from a list
914 owner
, slug
= get_slug()
916 user_name
= raw_input(light_magenta('Give me name of the unlucky one: '))
917 if user_name
.startswith('@'):
918 user_name
= user_name
[1:]
920 t
.lists
.members
.destroy(
922 owner_screen_name
=owner
,
923 screen_name
=user_name
)
924 printNicely(light_green('Gone.'))
926 printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
929 def list_subscribe(t
):
933 owner
, slug
= get_slug()
936 t
.lists
.subscribers
.create(
938 owner_screen_name
=owner
)
939 printNicely(light_green('Done.'))
942 light_magenta('I\'m sorry you can not subscribe to this list.'))
945 def list_unsubscribe(t
):
949 owner
, slug
= get_slug()
952 t
.lists
.subscribers
.destroy(
954 owner_screen_name
=owner
)
955 printNicely(light_green('Done.'))
958 light_magenta('I\'m sorry you can not unsubscribe to this list.'))
967 while next_cursor
!= 0:
968 res
= t
.lists
.ownerships(
969 screen_name
=g
['original_name'],
972 next_cursor
= res
['next_cursor']
976 printNicely(light_magenta('You own no lists :)'))
983 name
= raw_input(light_magenta('New list\'s name: '))
984 mode
= raw_input(light_magenta('New list\'s mode (public/private): '))
985 description
= raw_input(light_magenta('New list\'s description: '))
990 description
=description
)
991 printNicely(light_green(name
+ ' list is created.'))
993 printNicely(red('Oops something is wrong with Twitter :('))
1000 slug
= raw_input(light_magenta('Your list that you want to update: '))
1001 name
= raw_input(light_magenta('Update name (leave blank to unchange): '))
1002 mode
= raw_input(light_magenta('Update mode (public/private): '))
1003 description
= raw_input(light_magenta('Update description: '))
1007 slug
='-'.join(slug
.split()),
1008 owner_screen_name
=g
['original_name'],
1011 description
=description
)
1015 owner_screen_name
=g
['original_name'],
1017 description
=description
)
1018 printNicely(light_green(slug
+ ' list is updated.'))
1020 printNicely(red('Oops something is wrong with Twitter :('))
1027 slug
= raw_input(light_magenta('Your list that you want to update: '))
1030 slug
='-'.join(slug
.split()),
1031 owner_screen_name
=g
['original_name'])
1032 printNicely(light_green(slug
+ ' list is deleted.'))
1034 printNicely(red('Oops something is wrong with Twitter :('))
1041 t
= Twitter(auth
=authen())
1042 # List all lists or base on action
1044 g
['list_action'] = g
['stuff'].split()[0]
1051 'all_mem': list_members
,
1052 'all_sub': list_subscribers
,
1055 'sub': list_subscribe
,
1056 'unsub': list_unsubscribe
,
1059 'update': list_update
,
1063 return action_ary
[g
['list_action']](t
)
1065 printNicely(red('Please try again.'))
1070 Unix's command `cal`
1073 rel
= os
.popen('cal').read().split('\n')
1076 show_calendar(month
, date
, rel
)
1081 List and change theme
1085 for theme
in g
['themes']:
1086 line
= light_magenta(theme
)
1087 if c
['THEME'] == theme
:
1088 line
= ' ' * 2 + light_yellow('* ') + line
1090 line
= ' ' * 4 + line
1092 elif g
['stuff'] == 'current_as_default':
1094 def fixup(adict
, k
, v
):
1095 for key
in adict
.keys():
1098 elif type(adict
[key
]) is dict:
1099 fixup(adict
[key
], k
, v
)
1101 path
= os
.environ
.get(
1105 '')) + os
.sep
+ '.rainbow_config.json'
1106 data
= load_config(rainbow_config
)
1107 fixup(data
, 'THEME', c
['THEME'])
1109 with
open(path
, 'w') as out
:
1110 json
.dump(data
, out
, indent
= 4)
1111 os
.system('chmod 777 ' + path
)
1112 printNicely(light_green('Okay it will be applied from next time :)'))
1117 if g
['stuff'] != 'custom':
1118 new_config
= os
.path
.dirname(
1119 __file__
) + '/colorset/' + g
['stuff'] + '.json'
1121 new_config
= os
.environ
.get(
1122 'HOME', os
.environ
.get(
1124 '')) + os
.sep
+ '.rainbow_config.json'
1125 new_config
= load_config(new_config
)
1127 for nc
in new_config
:
1128 c
[nc
] = new_config
[nc
]
1129 # Update db and reset colors
1130 db
.theme_update(g
['stuff'])
1131 c
['THEME'] = g
['stuff']
1133 g
['decorated_name'] = color_func(
1134 c
['DECORATED_NAME'])(
1135 '[@' + g
['original_name'] + ']: ')
1136 printNicely(green('Theme changed.'))
1138 printNicely(red('No such theme exists.'))
1141 def help_discover():
1146 # Discover the world
1148 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
1149 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
1150 'You can try ' + light_green('trend US') + ' or ' + \
1151 light_green('trend JP Tokyo') + '.\n'
1152 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
1153 light_green('home 7') + ' will show 7 tweets.\n'
1154 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
1155 light_green('mentions 7') + ' will show 7 mention tweets.\n'
1156 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
1157 magenta('@mdo') + '.\n'
1158 usage
+= s
* 2 + light_green('view @mdo') + \
1159 ' will show ' + magenta('@mdo') + '\'s home.\n'
1160 usage
+= s
* 2 + light_green('s #AKB48') + ' will search for "' + \
1161 light_yellow('AKB48') + '" and return 5 newest tweet.\n'
1172 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
1173 usage
+= s
* 2 + light_green('t oops ') + \
1174 'will tweet "' + light_yellow('oops') + '" immediately.\n'
1176 light_green('rt 12 ') + ' will retweet to tweet with ' + \
1177 light_yellow('[id=12]') + '.\n'
1179 light_green('quote 12 ') + ' will quote the tweet with ' + \
1180 light_yellow('[id=12]') + '. If no extra text is added, ' + \
1181 'the quote will be canceled.\n'
1183 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
1184 light_yellow('[id=12]') + '.\n'
1185 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
1186 light_yellow('oops') + '" to tweet with ' + \
1187 light_yellow('[id=12]') + '.\n'
1189 light_green('fav 12 ') + ' will favorite the tweet with ' + \
1190 light_yellow('[id=12]') + '.\n'
1192 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
1193 light_yellow('[id=12]') + '.\n'
1195 light_green('del 12 ') + ' will delete tweet with ' + \
1196 light_yellow('[id=12]') + '.\n'
1197 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
1198 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
1199 usage
+= s
* 2 + light_green('open 12') + ' will open url in tweet with ' + \
1200 light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
1204 def help_messages():
1211 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
1212 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
1213 light_green('inbox 7') + ' will show newest 7 messages.\n'
1214 usage
+= s
* 2 + light_green('sent') + ' will show sent messages. ' + \
1215 light_green('sent 7') + ' will show newest 7 messages.\n'
1216 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
1217 magenta('@dtvd88') + '.\n'
1218 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
1219 light_yellow('[message_id=5]') + '.\n'
1223 def help_friends_and_followers():
1225 Friends and Followers
1228 # Follower and following
1230 usage
+= s
+ grey(u
'\u266A' + ' Friends and followers \n')
1232 light_green('ls fl') + \
1233 ' will list all followers (people who are following you).\n'
1235 light_green('ls fr') + \
1236 ' will list all friends (people who you are following).\n'
1237 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
1238 magenta('@dtvd88') + '.\n'
1239 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
1240 magenta('@dtvd88') + '.\n'
1241 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
1242 magenta('@dtvd88') + '.\n'
1243 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
1244 magenta('@dtvd88') + '.\n'
1245 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
1246 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
1247 magenta('@dtvd88') + '.\n'
1248 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
1249 magenta('@dtvd88') + '.\n'
1250 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
1251 magenta('@dtvd88') + ' as a spam account.\n'
1262 usage
+= s
+ grey(u
'\u266A' + ' Twitter list\n')
1263 usage
+= s
* 2 + light_green('list') + \
1264 ' will show all lists you are belong to.\n'
1265 usage
+= s
* 2 + light_green('list home') + \
1266 ' will show timeline of list. You will be asked for list\'s name.\n'
1267 usage
+= s
* 2 + light_green('list all_mem') + \
1268 ' will show list\'s all members.\n'
1269 usage
+= s
* 2 + light_green('list all_sub') + \
1270 ' will show list\'s all subscribers.\n'
1271 usage
+= s
* 2 + light_green('list add') + \
1272 ' will add specific person to a list owned by you.' + \
1273 ' You will be asked for list\'s name and person\'s name.\n'
1274 usage
+= s
* 2 + light_green('list rm') + \
1275 ' will remove specific person from a list owned by you.' + \
1276 ' You will be asked for list\'s name and person\'s name.\n'
1277 usage
+= s
* 2 + light_green('list sub') + \
1278 ' will subscribe you to a specific list.\n'
1279 usage
+= s
* 2 + light_green('list unsub') + \
1280 ' will unsubscribe you from a specific list.\n'
1281 usage
+= s
* 2 + light_green('list own') + \
1282 ' will show all list owned by you.\n'
1283 usage
+= s
* 2 + light_green('list new') + \
1284 ' will create a new list.\n'
1285 usage
+= s
* 2 + light_green('list update') + \
1286 ' will update a list owned by you.\n'
1287 usage
+= s
* 2 + light_green('list del') + \
1288 ' will delete a list owned by you.\n'
1299 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
1300 usage
+= s
* 2 + light_green('switch public #AKB') + \
1301 ' will switch to public stream and follow "' + \
1302 light_yellow('AKB') + '" keyword.\n'
1303 usage
+= s
* 2 + light_green('switch mine') + \
1304 ' will switch to your personal stream.\n'
1305 usage
+= s
* 2 + light_green('switch mine -f ') + \
1306 ' will prompt to enter the filter.\n'
1307 usage
+= s
* 3 + light_yellow('Only nicks') + \
1308 ' filter will decide nicks will be INCLUDE ONLY.\n'
1309 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
1310 ' filter will decide nicks will be EXCLUDE.\n'
1311 usage
+= s
* 2 + light_green('switch mine -d') + \
1312 ' will use the config\'s ONLY_LIST and IGNORE_LIST.\n'
1321 h
, w
= os
.popen('stty size', 'r').read().split()
1325 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
1326 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1327 usage
+= s
+ 'You are ' + \
1328 light_yellow('already') + ' on your personal stream.\n'
1329 usage
+= s
+ 'Any update from Twitter will show up ' + \
1330 light_yellow('immediately') + '.\n'
1331 usage
+= s
+ 'In addtion, following commands are available right now:\n'
1333 # Twitter help section
1335 usage
+= s
+ grey(u
'\u266A' + ' Twitter help\n')
1336 usage
+= s
* 2 + light_green('h discover') + \
1337 ' will show help for discover commands.\n'
1338 usage
+= s
* 2 + light_green('h tweets') + \
1339 ' will show help for tweets commands.\n'
1340 usage
+= s
* 2 + light_green('h messages') + \
1341 ' will show help for messages commands.\n'
1342 usage
+= s
* 2 + light_green('h friends_and_followers') + \
1343 ' will show help for friends and followers commands.\n'
1344 usage
+= s
* 2 + light_green('h list') + \
1345 ' will show help for list commands.\n'
1346 usage
+= s
* 2 + light_green('h stream') + \
1347 ' will show help for stream commands.\n'
1351 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
1352 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
1353 'will be evaluate by Python interpreter.\n'
1354 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
1355 ' for current month.\n'
1359 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
1360 usage
+= s
* 2 + light_green('theme') + ' will list available theme.' + \
1361 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
1362 ' theme immediately.\n'
1363 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
1364 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
1365 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
1369 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
1370 usage
+= s
+ 'Have fun and hang tight! \n'
1374 'discover': help_discover
,
1375 'tweets': help_tweets
,
1376 'messages': help_messages
,
1377 'friends_and_followers': help_friends_and_followers
,
1379 'stream': help_stream
,
1382 d
[g
['stuff'].strip()]()
1399 os
.system('rm -rf rainbow.db')
1400 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
1406 Reset prefix of line
1409 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
1412 printNicely(str(eval(g
['cmd'])))
1466 Listen to user's input
1471 ['public', 'mine'], # switch
1486 ['image'], # show image
1488 ['fl', 'fr'], # list
1515 g
['themes'] + ['current_as_default'], # theme
1520 'friends_and_followers',
1528 init_interactive_shell(d
)
1533 line
= raw_input(g
['decorated_name'])
1537 cmd
= line
.split()[0]
1541 # Save cmd to global variable and call process
1543 g
['stuff'] = ' '.join(line
.split()[1:])
1546 printNicely(red('OMG something is wrong with Twitter right now.'))
1547 # Not redisplay prefix
1548 if cmd
in ['switch', 't', 'rt', 'rep']:
1554 def stream(domain
, args
, name
='Rainbow Stream'):
1561 c
['USER_DOMAIN']: name
,
1562 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
1563 c
['SITE_DOMAIN']: name
,
1566 ascii_art(art_dict
[domain
])
1568 # These arguments are optional:
1570 timeout
=args
.timeout
,
1571 block
=not args
.no_block
,
1572 heartbeat_timeout
=args
.heartbeat_timeout
)
1576 if args
.track_keywords
:
1577 query_args
['track'] = args
.track_keywords
1580 stream
= TwitterStream(
1586 if domain
== c
['USER_DOMAIN']:
1587 tweet_iter
= stream
.user(**query_args
)
1588 elif domain
== c
['SITE_DOMAIN']:
1589 tweet_iter
= stream
.site(**query_args
)
1591 if args
.track_keywords
:
1592 tweet_iter
= stream
.statuses
.filter(**query_args
)
1594 tweet_iter
= stream
.statuses
.sample()
1596 # Iterate over the stream.
1597 for tweet
in tweet_iter
:
1599 printNicely("-- None --")
1600 elif tweet
is Timeout
:
1601 printNicely("-- Timeout --")
1602 elif tweet
is HeartbeatTimeout
:
1603 printNicely("-- Heartbeat Timeout --")
1604 elif tweet
is Hangup
:
1605 printNicely("-- Hangup --")
1606 elif tweet
.get('text'):
1609 iot
=args
.image_on_term
,
1610 keyword
=args
.track_keywords
,
1614 except TwitterHTTPError
:
1617 magenta("We have maximum connection problem with twitter'stream API right now :("))
1624 # Spawn stream process
1625 args
= parse_arguments()
1627 get_decorated_name()
1629 except TwitterHTTPError
:
1632 magenta("Something wrong with Twitter Oauth right now :("))
1634 magenta("Please delete ~/.rainbow_oauth and try again."))
1636 os
.system('rm -rf rainbow.db')
1644 g
['original_name']))
1647 # Start listen process
1651 g
['stream_pid'] = p
.pid
1652 g
['iot'] = args
.image_on_term