2 Colorful user's timeline stream
4 from multiprocessing
import Process
14 from twitter
.stream
import TwitterStream
, Timeout
, HeartbeatTimeout
, Hangup
15 from twitter
.api
import *
16 from twitter
.oauth
import OAuth
, read_token_file
17 from twitter
.oauth_dance
import oauth_dance
18 from twitter
.util
import printNicely
19 from StringIO
import StringIO
24 from .consumer
import *
25 from .interactive
import *
27 from .c_image
import *
68 def parse_arguments():
72 parser
= argparse
.ArgumentParser(description
=__doc__
or "")
76 help='Timeout for the stream (seconds).')
79 '--heartbeat-timeout',
80 help='Set heartbeat timeout.',
86 help='Set stream to non-blocking.')
90 help='Search the stream for specific text.')
94 help='Filter specific screen_name.')
98 help='Ignore specific screen_name.')
103 help='Display all image on terminal.')
104 return parser
.parse_args()
109 Authenticate with Twitter OAuth
111 # When using rainbow stream you must authorize.
112 twitter_credential
= os
.environ
.get(
116 '')) + os
.sep
+ '.rainbow_oauth'
117 if not os
.path
.exists(twitter_credential
):
118 oauth_dance("Rainbow Stream",
122 oauth_token
, oauth_token_secret
= read_token_file(twitter_credential
)
130 def get_decorated_name():
132 Beginning of every line
134 t
= Twitter(auth
=authen())
135 name
= '@' + t
.account
.verify_credentials()['screen_name']
136 g
['original_name'] = name
[1:]
137 g
['decorated_name'] = color_func(c
['DECORATED_NAME'])('[' + name
+ ']: ')
138 g
['ascii_art'] = True
140 files
= os
.listdir('rainbowstream/colorset')
141 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
143 db
.theme_store(c
['theme'])
151 target
= g
['stuff'].split()[0]
154 args
= parse_arguments()
156 if g
['stuff'].split()[-1] == '-f':
157 only
= raw_input('Only nicks: ')
158 ignore
= raw_input('Ignore nicks: ')
159 args
.filter = filter(None, only
.split(','))
160 args
.ignore
= filter(None, ignore
.split(','))
161 elif g
['stuff'].split()[-1] == '-d':
162 args
.filter = c
['ONLY_LIST']
163 args
.ignore
= c
['IGNORE_LIST']
165 printNicely(red('Sorry, wrong format.'))
169 if target
== 'public':
170 keyword
= g
['stuff'].split()[1]
171 if keyword
[0] == '#':
172 keyword
= keyword
[1:]
174 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
175 args
.track_keywords
= keyword
183 g
['stream_pid'] = p
.pid
186 elif target
== 'mine':
188 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
197 g
['stream_pid'] = p
.pid
200 printNicely(cyan('Only: ' + str(args
.filter)))
202 printNicely(red('Ignore: ' + str(args
.ignore
)))
204 g
['ascii_art'] = True
206 printNicely(red('Sorry I can\'t understand.'))
213 t
= Twitter(auth
=authen())
214 # Get country and town
216 country
= g
['stuff'].split()[0]
220 town
= g
['stuff'].split()[1]
224 avail
= t
.trends
.available()
227 trends
= t
.trends
.place(_id
=1)[0]['trends']
230 for location
in avail
:
231 # Search for country and Town
233 if location
['countryCode'] == country \
234 and location
['placeType']['name'] == 'Town' \
235 and location
['name'] == town
:
236 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
238 # Search for country only
240 if location
['countryCode'] == country \
241 and location
['placeType']['name'] == 'Country':
242 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
250 t
= Twitter(auth
=authen())
251 num
= c
['HOME_TWEET_NUM']
252 if g
['stuff'].isdigit():
253 num
= int(g
['stuff'])
254 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
255 draw(t
=tweet
, iot
=g
['iot'])
263 t
= Twitter(auth
=authen())
264 user
= g
['stuff'].split()[0]
267 num
= int(g
['stuff'].split()[1])
269 num
= c
['HOME_TWEET_NUM']
270 for tweet
in reversed(t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
271 draw(t
=tweet
, iot
=g
['iot'])
274 printNicely(red('A name should begin with a \'@\''))
281 t
= Twitter(auth
=authen())
282 num
= c
['HOME_TWEET_NUM']
283 if g
['stuff'].isdigit():
284 num
= int(g
['stuff'])
285 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
286 draw(t
=tweet
, iot
=g
['iot'])
294 t
= Twitter(auth
=authen())
295 t
.statuses
.update(status
=g
['stuff'])
302 t
= Twitter(auth
=authen())
304 id = int(g
['stuff'].split()[0])
306 printNicely(red('Sorry I can\'t understand.'))
308 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
309 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
316 t
= Twitter(auth
=authen())
319 id = int(g
['stuff'].split()[0])
321 printNicely(red('Sorry I can\'t understand.'))
323 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
324 # Get display num if exist
326 num
= int(g
['stuff'].split()[1])
328 num
= c
['RETWEETS_SHOW_NUM']
329 # Get result and display
330 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
332 printNicely(magenta('This tweet has no retweet.'))
334 for tweet
in reversed(rt_ary
):
335 draw(t
=tweet
, iot
=g
['iot'])
343 t
= Twitter(auth
=authen())
345 id = int(g
['stuff'].split()[0])
347 printNicely(red('Sorry I can\'t understand.'))
349 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
350 t
.favorites
.create(_id
=tid
, include_entities
=False)
351 printNicely(green('Favorited.'))
352 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
360 t
= Twitter(auth
=authen())
362 id = int(g
['stuff'].split()[0])
364 printNicely(red('Sorry I can\'t understand.'))
366 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
367 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
368 status
= ' '.join(g
['stuff'].split()[1:])
369 status
= '@' + user
+ ' ' + status
.decode('utf-8')
370 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
377 t
= Twitter(auth
=authen())
379 rid
= int(g
['stuff'].split()[0])
381 printNicely(red('Sorry I can\'t understand.'))
383 tid
= db
.rainbow_to_tweet_query(rid
)[0].tweet_id
384 t
.statuses
.destroy(id=tid
)
385 printNicely(green('Okay it\'s gone.'))
392 t
= Twitter(auth
=authen())
394 id = int(g
['stuff'].split()[0])
396 printNicely(red('Sorry I can\'t understand.'))
398 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
399 t
.favorites
.destroy(_id
=tid
)
400 printNicely(green('Okay it\'s unfavorited.'))
401 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
409 t
= Twitter(auth
=authen())
410 if g
['stuff'].startswith('#'):
411 rel
= t
.search
.tweets(q
=g
['stuff'])['statuses']
413 printNicely('Newest tweets:')
414 for i
in reversed(xrange(c
['SEARCH_MAX_RECORD'])):
417 keyword
=g
['stuff'].strip()[1:])
420 printNicely(magenta('I\'m afraid there is no result'))
422 printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
427 Send a direct message
429 t
= Twitter(auth
=authen())
430 user
= g
['stuff'].split()[0]
431 if user
[0].startswith('@'):
433 content
= g
['stuff'].split()[1]
435 printNicely(red('Sorry I can\'t understand.'))
436 t
.direct_messages
.new(
437 screen_name
=user
[1:],
440 printNicely(green('Message sent.'))
442 printNicely(red('A name should begin with a \'@\''))
449 t
= Twitter(auth
=authen())
451 target
= g
['stuff'].split()[0]
452 if target
!= 'image':
454 id = int(g
['stuff'].split()[1])
455 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
456 tweet
= t
.statuses
.show(id=tid
)
457 media
= tweet
['entities']['media']
459 res
= requests
.get(m
['media_url'])
460 img
= Image
.open(StringIO(res
.content
))
463 printNicely(red('Sorry I can\'t show this image.'))
468 List friends for followers
470 t
= Twitter(auth
=authen())
473 name
= g
['stuff'].split()[1]
474 if name
.startswith('@'):
477 printNicely(red('A name should begin with a \'@\''))
478 raise Exception('Invalid name')
480 name
= g
['original_name']
481 # Get list followers or friends
483 target
= g
['stuff'].split()[0]
485 printNicely(red('Omg some syntax is wrong.'))
487 d
= {'fl': 'followers', 'fr': 'friends'}
491 while next_cursor
!= 0:
492 list = getattr(t
, d
[target
]).list(
496 include_entities
=False,
498 for u
in list['users']:
499 rel
[u
['name']] = '@' + u
['screen_name']
500 next_cursor
= list['next_cursor']
502 printNicely('All: ' + str(len(rel
)) + ' people.')
504 user
= ' ' + cycle_color(name
) + grey(' ' + rel
[name
] + ' ')
510 Inbox direct messages
512 t
= Twitter(auth
=authen())
513 num
= c
['MESSAGES_DISPLAY']
515 if g
['stuff'].isdigit():
518 # Max message per page is 20 so we have to loop
520 rel
= rel
+ t
.direct_messages(
523 include_entities
=False,
528 rel
= rel
+ t
.direct_messages(
531 include_entities
=False,
535 printNicely('Inbox: newest ' + str(len(rel
)) + ' messages.')
536 for m
in reversed(rel
):
545 t
= Twitter(auth
=authen())
546 num
= c
['MESSAGES_DISPLAY']
548 if g
['stuff'].isdigit():
549 num
= int(g
['stuff'])
551 # Max message per page is 20 so we have to loop
553 rel
= rel
+ t
.direct_messages
.sent(
556 include_entities
=False,
561 rel
= rel
+ t
.direct_messages
.sent(
564 include_entities
=False,
568 printNicely('Sent: newest ' + str(len(rel
)) + ' messages.')
569 for m
in reversed(rel
):
578 t
= Twitter(auth
=authen())
580 rid
= int(g
['stuff'].split()[0])
582 printNicely(red('Sorry I can\'t understand.'))
583 mid
= db
.rainbow_to_message_query(rid
)[0].message_id
584 t
.direct_messages
.destroy(id=mid
)
585 printNicely(green('Message deleted.'))
590 Show profile of a specific user
592 t
= Twitter(auth
=authen())
593 screen_name
= g
['stuff'].split()[0]
594 if screen_name
.startswith('@'):
597 screen_name
=screen_name
[1:],
598 include_entities
=False)
599 show_profile(user
, g
['iot'])
601 printNicely(red('Omg no user.'))
603 printNicely(red('A name should begin with a \'@\''))
610 t
= Twitter(auth
=authen())
611 screen_name
= g
['stuff'].split()[0]
612 if screen_name
.startswith('@'):
613 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
614 printNicely(green('You are following ' + screen_name
+ ' now!'))
616 printNicely(red('A name should begin with a \'@\''))
623 t
= Twitter(auth
=authen())
624 screen_name
= g
['stuff'].split()[0]
625 if screen_name
.startswith('@'):
626 t
.friendships
.destroy(
627 screen_name
=screen_name
[1:],
628 include_entities
=False)
629 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
631 printNicely(red('A name should begin with a \'@\''))
638 t
= Twitter(auth
=authen())
640 screen_name
= g
['stuff'].split()[0]
642 printNicely(red('A name should be specified. '))
644 if screen_name
.startswith('@'):
645 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
646 if isinstance(rel
, dict):
647 printNicely(green(screen_name
+ ' is muted.'))
649 printNicely(red(rel
))
651 printNicely(red('A name should begin with a \'@\''))
658 t
= Twitter(auth
=authen())
660 screen_name
= g
['stuff'].split()[0]
662 printNicely(red('A name should be specified. '))
664 if screen_name
.startswith('@'):
665 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
666 if isinstance(rel
, dict):
667 printNicely(green(screen_name
+ ' is unmuted.'))
669 printNicely(red(rel
))
671 printNicely(red('A name should begin with a \'@\''))
678 t
= Twitter(auth
=authen())
683 while next_cursor
!= 0:
684 list = t
.mutes
.users
.list(
685 screen_name
=g
['original_name'],
688 include_entities
=False,
690 for u
in list['users']:
691 rel
[u
['name']] = '@' + u
['screen_name']
692 next_cursor
= list['next_cursor']
694 printNicely('All: ' + str(len(rel
)) + ' people.')
696 user
= ' ' + cycle_color(name
) + grey(' ' + rel
[name
] + ' ')
704 t
= Twitter(auth
=authen())
705 screen_name
= g
['stuff'].split()[0]
706 if screen_name
.startswith('@'):
708 screen_name
=screen_name
[1:],
709 include_entities
=False,
711 printNicely(green('You blocked ' + screen_name
+ '.'))
713 printNicely(red('A name should begin with a \'@\''))
720 t
= Twitter(auth
=authen())
721 screen_name
= g
['stuff'].split()[0]
722 if screen_name
.startswith('@'):
724 screen_name
=screen_name
[1:],
725 include_entities
=False,
727 printNicely(green('Unblock ' + screen_name
+ ' success!'))
729 printNicely(red('A name should begin with a \'@\''))
734 Report a user as a spam account
736 t
= Twitter(auth
=authen())
737 screen_name
= g
['stuff'].split()[0]
738 if screen_name
.startswith('@'):
740 screen_name
=screen_name
[1:])
741 printNicely(green('You reported ' + screen_name
+ '.'))
743 printNicely(red('Sorry I can\'t understand.'))
751 rel
= os
.popen('cal').read().split('\n')
753 month
= random_rainbow(month
)
755 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
756 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
761 ary
= line
.split(' ')
762 ary
= map(lambda x
: on_grey(x
) if x
== today
else grey(x
), ary
)
763 printNicely(' '.join(ary
))
768 List and change theme
772 for theme
in g
['themes']:
774 # Detect custom config
775 if theme
== 'custom':
776 line
+= light_magenta('custom')
777 exists
= db
.theme_query()
778 themes
= [t
.theme_name
for t
in exists
]
779 if themes
[0] == 'custom':
780 line
+= light_magenta(' (applied)')
782 line
+= light_magenta(' (not specified)')
784 line
+= light_magenta(theme
)
785 if c
['theme'] == theme
:
786 line
= ' '*2 + light_yellow('* ') + line
794 new_config
= 'rainbowstream/colorset/' + g
['stuff'] + '.json'
795 new_config
= load_config(new_config
)
797 for nc
in new_config
:
798 c
[nc
] = new_config
[nc
]
800 db
.theme_update(g
['stuff'])
801 g
['decorated_name'] = color_func(
802 c
['DECORATED_NAME'])(
803 '[@' + g
['original_name'] + ']: ')
804 printNicely(green('Theme changed.'))
806 printNicely(red('Sorry, config file is broken!'))
814 h
, w
= os
.popen('stty size', 'r').read().split()
818 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
819 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
820 usage
+= s
+ 'You are ' + \
821 light_yellow('already') + ' on your personal stream.\n'
822 usage
+= s
+ 'Any update from Twitter will show up ' + \
823 light_yellow('immediately') + '.\n'
824 usage
+= s
+ 'In addtion, following commands are available right now:\n'
828 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
829 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
830 'You can try ' + light_green('trend US') + ' or ' + \
831 light_green('trend JP Tokyo') + '.\n'
832 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
833 light_green('home 7') + ' will show 7 tweets.\n'
834 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
835 light_green('mentions 7') + ' will show 7 mention tweets.\n'
836 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
837 magenta('@mdo') + '.\n'
838 usage
+= s
* 2 + light_green('view @mdo') + \
839 ' will show ' + magenta('@mdo') + '\'s home.\n'
840 usage
+= s
* 2 + light_green('s #AKB48') + ' will search for "' + \
841 light_yellow('AKB48') + '" and return 5 newest tweet.\n'
845 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
846 usage
+= s
* 2 + light_green('t oops ') + \
847 'will tweet "' + light_yellow('oops') + '" immediately.\n'
849 light_green('rt 12 ') + ' will retweet to tweet with ' + \
850 light_yellow('[id=12]') + '.\n'
852 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
853 light_yellow('[id=12]') + '.\n'
854 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
855 light_yellow('oops') + '" to tweet with ' + \
856 light_yellow('[id=12]') + '.\n'
858 light_green('fav 12 ') + ' will favorite the tweet with ' + \
859 light_yellow('[id=12]') + '.\n'
861 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
862 light_yellow('[id=12]') + '.\n'
864 light_green('del 12 ') + ' will delete tweet with ' + \
865 light_yellow('[id=12]') + '.\n'
866 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
867 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
871 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
872 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
873 light_green('inbox 7') + ' will show newest 7 messages.\n'
874 usage
+= s
* 2 + light_green('sent') + ' will show sent messages. ' + \
875 light_green('sent 7') + ' will show newest 7 messages.\n'
876 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
877 magenta('@dtvd88') + '.\n'
878 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
879 light_yellow('[message_id=5]') + '.\n'
881 # Follower and following
883 usage
+= s
+ grey(u
'\u266A' + ' Fiends and followers \n')
885 light_green('ls fl') + \
886 ' will list all followers (people who are following you).\n'
888 light_green('ls fr') + \
889 ' will list all friends (people who you are following).\n'
890 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
891 magenta('@dtvd88') + '.\n'
892 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
893 magenta('@dtvd88') + '.\n'
894 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
895 magenta('@dtvd88') + '.\n'
896 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
897 magenta('@dtvd88') + '.\n'
898 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
899 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
900 magenta('@dtvd88') + '.\n'
901 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
902 magenta('@dtvd88') + '.\n'
903 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
904 magenta('@dtvd88') + ' as a spam account.\n'
908 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
909 usage
+= s
* 2 + light_green('switch public #AKB') + \
910 ' will switch to public stream and follow "' + \
911 light_yellow('AKB') + '" keyword.\n'
912 usage
+= s
* 2 + light_green('switch mine') + \
913 ' will switch to your personal stream.\n'
914 usage
+= s
* 2 + light_green('switch mine -f ') + \
915 ' will prompt to enter the filter.\n'
916 usage
+= s
* 3 + light_yellow('Only nicks') + \
917 ' filter will decide nicks will be INCLUDE ONLY.\n'
918 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
919 ' filter will decide nicks will be EXCLUDE.\n'
920 usage
+= s
* 2 + light_green('switch mine -d') + \
921 ' will use the config\'s ONLY_LIST and IGNORE_LIST.\n'
925 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
926 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
927 'will be evaluate by Python interpreter.\n'
928 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
929 ' for current month.\n'
933 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
934 usage
+= s
* 2 + light_green('theme') + ' will list available theme.' + \
935 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
936 ' theme immediately.\n'
937 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
938 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
939 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
943 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
944 usage
+= s
+ 'Have fun and hang tight! \n'
960 os
.system('rm -rf rainbow.db')
961 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
970 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
973 printNicely(eval(g
['cmd']))
1024 Listen to user's input
1029 ['public', 'mine'], # switch
1043 ['image'], # show image
1044 ['fl', 'fr'], # list
1058 g
['themes'], # theme
1064 init_interactive_shell(d
)
1069 line
= raw_input(g
['decorated_name'])
1073 cmd
= line
.split()[0]
1077 # Save cmd to global variable and call process
1079 g
['stuff'] = ' '.join(line
.split()[1:])
1081 except Exception as e
:
1083 printNicely(red('OMG something is wrong with Twitter right now.'))
1084 # Not redisplay prefix
1085 if cmd
in ['switch', 't', 'rt', 'rep']:
1091 def stream(domain
, args
, name
='Rainbow Stream'):
1098 c
['USER_DOMAIN']: name
,
1099 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
1100 c
['SITE_DOMAIN']: 'Site Stream',
1103 ascii_art(art_dict
[domain
])
1105 # These arguments are optional:
1107 timeout
=args
.timeout
,
1108 block
=not args
.no_block
,
1109 heartbeat_timeout
=args
.heartbeat_timeout
)
1113 if args
.track_keywords
:
1114 query_args
['track'] = args
.track_keywords
1117 stream
= TwitterStream(
1122 if domain
== c
['USER_DOMAIN']:
1123 tweet_iter
= stream
.user(**query_args
)
1124 elif domain
== c
['SITE_DOMAIN']:
1125 tweet_iter
= stream
.site(**query_args
)
1127 if args
.track_keywords
:
1128 tweet_iter
= stream
.statuses
.filter(**query_args
)
1130 tweet_iter
= stream
.statuses
.sample()
1132 # Iterate over the stream.
1134 for tweet
in tweet_iter
:
1136 printNicely("-- None --")
1137 elif tweet
is Timeout
:
1138 printNicely("-- Timeout --")
1139 elif tweet
is HeartbeatTimeout
:
1140 printNicely("-- Heartbeat Timeout --")
1141 elif tweet
is Hangup
:
1142 printNicely("-- Hangup --")
1143 elif tweet
.get('text'):
1146 iot
=args
.image_on_term
,
1147 keyword
=args
.track_keywords
,
1153 magenta("I'm afraid we have problem with twitter'S maximum connection."))
1154 printNicely(magenta("Let's try again later."))
1161 # Spawn stream process
1162 args
= parse_arguments()
1163 get_decorated_name()
1169 g
['original_name']))
1172 # Start listen process
1176 g
['stream_pid'] = p
.pid
1177 g
['iot'] = args
.image_on_term