ab4c847a9e2cbdbed876ea4731a3d66840014792
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']
144 db
.theme_store(c
['theme'])
152 target
= g
['stuff'].split()[0]
155 args
= parse_arguments()
157 if g
['stuff'].split()[-1] == '-f':
158 only
= raw_input('Only nicks: ')
159 ignore
= raw_input('Ignore nicks: ')
160 args
.filter = filter(None, only
.split(','))
161 args
.ignore
= filter(None, ignore
.split(','))
162 elif g
['stuff'].split()[-1] == '-d':
163 args
.filter = c
['ONLY_LIST']
164 args
.ignore
= c
['IGNORE_LIST']
166 printNicely(red('Sorry, wrong format.'))
170 if target
== 'public':
171 keyword
= g
['stuff'].split()[1]
172 if keyword
[0] == '#':
173 keyword
= keyword
[1:]
175 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
176 args
.track_keywords
= keyword
184 g
['stream_pid'] = p
.pid
187 elif target
== 'mine':
189 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
198 g
['stream_pid'] = p
.pid
201 printNicely(cyan('Only: ' + str(args
.filter)))
203 printNicely(red('Ignore: ' + str(args
.ignore
)))
205 g
['ascii_art'] = True
207 printNicely(red('Sorry I can\'t understand.'))
214 t
= Twitter(auth
=authen())
215 # Get country and town
217 country
= g
['stuff'].split()[0]
221 town
= g
['stuff'].split()[1]
225 avail
= t
.trends
.available()
228 trends
= t
.trends
.place(_id
=1)[0]['trends']
231 for location
in avail
:
232 # Search for country and Town
234 if location
['countryCode'] == country \
235 and location
['placeType']['name'] == 'Town' \
236 and location
['name'] == town
:
237 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
239 # Search for country only
241 if location
['countryCode'] == country \
242 and location
['placeType']['name'] == 'Country':
243 trends
= t
.trends
.place(_id
=location
['woeid'])[0]['trends']
251 t
= Twitter(auth
=authen())
252 num
= c
['HOME_TWEET_NUM']
253 if g
['stuff'].isdigit():
254 num
= int(g
['stuff'])
255 for tweet
in reversed(t
.statuses
.home_timeline(count
=num
)):
256 draw(t
=tweet
, iot
=g
['iot'])
264 t
= Twitter(auth
=authen())
265 user
= g
['stuff'].split()[0]
268 num
= int(g
['stuff'].split()[1])
270 num
= c
['HOME_TWEET_NUM']
271 for tweet
in reversed(t
.statuses
.user_timeline(count
=num
, screen_name
=user
[1:])):
272 draw(t
=tweet
, iot
=g
['iot'])
275 printNicely(red('A name should begin with a \'@\''))
282 t
= Twitter(auth
=authen())
283 num
= c
['HOME_TWEET_NUM']
284 if g
['stuff'].isdigit():
285 num
= int(g
['stuff'])
286 for tweet
in reversed(t
.statuses
.mentions_timeline(count
=num
)):
287 draw(t
=tweet
, iot
=g
['iot'])
295 t
= Twitter(auth
=authen())
296 t
.statuses
.update(status
=g
['stuff'])
303 t
= Twitter(auth
=authen())
305 id = int(g
['stuff'].split()[0])
307 printNicely(red('Sorry I can\'t understand.'))
309 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
310 t
.statuses
.retweet(id=tid
, include_entities
=False, trim_user
=True)
317 t
= Twitter(auth
=authen())
320 id = int(g
['stuff'].split()[0])
322 printNicely(red('Sorry I can\'t understand.'))
324 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
325 # Get display num if exist
327 num
= int(g
['stuff'].split()[1])
329 num
= c
['RETWEETS_SHOW_NUM']
330 # Get result and display
331 rt_ary
= t
.statuses
.retweets(id=tid
, count
=num
)
333 printNicely(magenta('This tweet has no retweet.'))
335 for tweet
in reversed(rt_ary
):
336 draw(t
=tweet
, iot
=g
['iot'])
344 t
= Twitter(auth
=authen())
346 id = int(g
['stuff'].split()[0])
348 printNicely(red('Sorry I can\'t understand.'))
350 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
351 t
.favorites
.create(_id
=tid
, include_entities
=False)
352 printNicely(green('Favorited.'))
353 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
361 t
= Twitter(auth
=authen())
363 id = int(g
['stuff'].split()[0])
365 printNicely(red('Sorry I can\'t understand.'))
367 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
368 user
= t
.statuses
.show(id=tid
)['user']['screen_name']
369 status
= ' '.join(g
['stuff'].split()[1:])
370 status
= '@' + user
+ ' ' + status
.decode('utf-8')
371 t
.statuses
.update(status
=status
, in_reply_to_status_id
=tid
)
378 t
= Twitter(auth
=authen())
380 rid
= int(g
['stuff'].split()[0])
382 printNicely(red('Sorry I can\'t understand.'))
384 tid
= db
.rainbow_to_tweet_query(rid
)[0].tweet_id
385 t
.statuses
.destroy(id=tid
)
386 printNicely(green('Okay it\'s gone.'))
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 t
.favorites
.destroy(_id
=tid
)
401 printNicely(green('Okay it\'s unfavorited.'))
402 draw(t
.statuses
.show(id=tid
), iot
=g
['iot'])
410 t
= Twitter(auth
=authen())
411 if g
['stuff'].startswith('#'):
412 rel
= t
.search
.tweets(q
=g
['stuff'])['statuses']
414 printNicely('Newest tweets:')
415 for i
in reversed(xrange(c
['SEARCH_MAX_RECORD'])):
418 keyword
=g
['stuff'].strip()[1:])
421 printNicely(magenta('I\'m afraid there is no result'))
423 printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
428 Send a direct message
430 t
= Twitter(auth
=authen())
431 user
= g
['stuff'].split()[0]
432 if user
[0].startswith('@'):
434 content
= g
['stuff'].split()[1]
436 printNicely(red('Sorry I can\'t understand.'))
437 t
.direct_messages
.new(
438 screen_name
=user
[1:],
441 printNicely(green('Message sent.'))
443 printNicely(red('A name should begin with a \'@\''))
450 t
= Twitter(auth
=authen())
452 target
= g
['stuff'].split()[0]
453 if target
!= 'image':
455 id = int(g
['stuff'].split()[1])
456 tid
= db
.rainbow_to_tweet_query(id)[0].tweet_id
457 tweet
= t
.statuses
.show(id=tid
)
458 media
= tweet
['entities']['media']
460 res
= requests
.get(m
['media_url'])
461 img
= Image
.open(StringIO(res
.content
))
464 printNicely(red('Sorry I can\'t show this image.'))
469 List friends for followers
471 t
= Twitter(auth
=authen())
474 name
= g
['stuff'].split()[1]
475 if name
.startswith('@'):
478 printNicely(red('A name should begin with a \'@\''))
479 raise Exception('Invalid name')
481 name
= g
['original_name']
482 # Get list followers or friends
484 target
= g
['stuff'].split()[0]
486 printNicely(red('Omg some syntax is wrong.'))
488 d
= {'fl': 'followers', 'fr': 'friends'}
492 while next_cursor
!= 0:
493 list = getattr(t
, d
[target
]).list(
497 include_entities
=False,
499 for u
in list['users']:
500 rel
[u
['name']] = '@' + u
['screen_name']
501 next_cursor
= list['next_cursor']
503 printNicely('All: ' + str(len(rel
)) + ' people.')
505 user
= ' ' + cycle_color(name
) + grey(' ' + rel
[name
] + ' ')
511 Inbox direct messages
513 t
= Twitter(auth
=authen())
514 num
= c
['MESSAGES_DISPLAY']
516 if g
['stuff'].isdigit():
519 # Max message per page is 20 so we have to loop
521 rel
= rel
+ t
.direct_messages(
524 include_entities
=False,
529 rel
= rel
+ t
.direct_messages(
532 include_entities
=False,
536 printNicely('Inbox: newest ' + str(len(rel
)) + ' messages.')
537 for m
in reversed(rel
):
546 t
= Twitter(auth
=authen())
547 num
= c
['MESSAGES_DISPLAY']
549 if g
['stuff'].isdigit():
550 num
= int(g
['stuff'])
552 # Max message per page is 20 so we have to loop
554 rel
= rel
+ t
.direct_messages
.sent(
557 include_entities
=False,
562 rel
= rel
+ t
.direct_messages
.sent(
565 include_entities
=False,
569 printNicely('Sent: newest ' + str(len(rel
)) + ' messages.')
570 for m
in reversed(rel
):
579 t
= Twitter(auth
=authen())
581 rid
= int(g
['stuff'].split()[0])
583 printNicely(red('Sorry I can\'t understand.'))
584 mid
= db
.rainbow_to_message_query(rid
)[0].message_id
585 t
.direct_messages
.destroy(id=mid
)
586 printNicely(green('Message deleted.'))
591 Show profile of a specific user
593 t
= Twitter(auth
=authen())
594 screen_name
= g
['stuff'].split()[0]
595 if screen_name
.startswith('@'):
598 screen_name
=screen_name
[1:],
599 include_entities
=False)
600 show_profile(user
, g
['iot'])
602 printNicely(red('Omg no user.'))
604 printNicely(red('A name should begin with a \'@\''))
611 t
= Twitter(auth
=authen())
612 screen_name
= g
['stuff'].split()[0]
613 if screen_name
.startswith('@'):
614 t
.friendships
.create(screen_name
=screen_name
[1:], follow
=True)
615 printNicely(green('You are following ' + screen_name
+ ' now!'))
617 printNicely(red('A name should begin with a \'@\''))
624 t
= Twitter(auth
=authen())
625 screen_name
= g
['stuff'].split()[0]
626 if screen_name
.startswith('@'):
627 t
.friendships
.destroy(
628 screen_name
=screen_name
[1:],
629 include_entities
=False)
630 printNicely(green('Unfollow ' + screen_name
+ ' success!'))
632 printNicely(red('A name should begin with a \'@\''))
639 t
= Twitter(auth
=authen())
641 screen_name
= g
['stuff'].split()[0]
643 printNicely(red('A name should be specified. '))
645 if screen_name
.startswith('@'):
646 rel
= t
.mutes
.users
.create(screen_name
=screen_name
[1:])
647 if isinstance(rel
, dict):
648 printNicely(green(screen_name
+ ' is muted.'))
650 printNicely(red(rel
))
652 printNicely(red('A name should begin with a \'@\''))
659 t
= Twitter(auth
=authen())
661 screen_name
= g
['stuff'].split()[0]
663 printNicely(red('A name should be specified. '))
665 if screen_name
.startswith('@'):
666 rel
= t
.mutes
.users
.destroy(screen_name
=screen_name
[1:])
667 if isinstance(rel
, dict):
668 printNicely(green(screen_name
+ ' is unmuted.'))
670 printNicely(red(rel
))
672 printNicely(red('A name should begin with a \'@\''))
679 t
= Twitter(auth
=authen())
684 while next_cursor
!= 0:
685 list = t
.mutes
.users
.list(
686 screen_name
=g
['original_name'],
689 include_entities
=False,
691 for u
in list['users']:
692 rel
[u
['name']] = '@' + u
['screen_name']
693 next_cursor
= list['next_cursor']
695 printNicely('All: ' + str(len(rel
)) + ' people.')
697 user
= ' ' + cycle_color(name
) + grey(' ' + rel
[name
] + ' ')
705 t
= Twitter(auth
=authen())
706 screen_name
= g
['stuff'].split()[0]
707 if screen_name
.startswith('@'):
709 screen_name
=screen_name
[1:],
710 include_entities
=False,
712 printNicely(green('You blocked ' + screen_name
+ '.'))
714 printNicely(red('A name should begin with a \'@\''))
721 t
= Twitter(auth
=authen())
722 screen_name
= g
['stuff'].split()[0]
723 if screen_name
.startswith('@'):
725 screen_name
=screen_name
[1:],
726 include_entities
=False,
728 printNicely(green('Unblock ' + screen_name
+ ' success!'))
730 printNicely(red('A name should begin with a \'@\''))
735 Report a user as a spam account
737 t
= Twitter(auth
=authen())
738 screen_name
= g
['stuff'].split()[0]
739 if screen_name
.startswith('@'):
741 screen_name
=screen_name
[1:])
742 printNicely(green('You reported ' + screen_name
+ '.'))
744 printNicely(red('Sorry I can\'t understand.'))
752 rel
= os
.popen('cal').read().split('\n')
754 month
= random_rainbow(month
)
756 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
757 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
762 ary
= line
.split(' ')
763 ary
= map(lambda x
: on_grey(x
) if x
== today
else grey(x
), ary
)
764 printNicely(' '.join(ary
))
769 List and change theme
773 for theme
in g
['themes']:
775 # Detect custom config
776 if theme
== 'custom':
777 line
+= light_magenta('custom')
778 custom_path
= os
.environ
.get(
780 os
.environ
.get('USERPROFILE',
781 '')) + os
.sep
+ '.rainbow_config.json'
782 if not os
.path
.exists(custom_path
):
783 line
+= light_magenta(' (create your own config at ~/.rainbow_config.json)')
785 line
+= light_magenta(' (loaded)')
787 line
+= light_magenta(theme
)
788 if c
['theme'] == theme
:
789 line
= ' '*2 + light_yellow('* ') + line
797 c
['theme'] = g
['stuff']
798 if g
['stuff'] != 'custom':
799 new_config
= 'rainbowstream/colorset/' + g
['stuff'] + '.json'
801 new_config
= os
.environ
.get(
802 'HOME',os
.environ
.get(
804 '')) + os
.sep
+ '.rainbow_config.json'
805 new_config
= load_config(new_config
)
807 for nc
in new_config
:
808 c
[nc
] = new_config
[nc
]
809 # Update db and reset colors
810 db
.theme_update(g
['stuff'])
811 g
['decorated_name'] = color_func(
812 c
['DECORATED_NAME'])(
813 '[@' + g
['original_name'] + ']: ')
814 printNicely(green('Theme changed.'))
816 if g
['stuff'] == 'custom':
817 printNicely(red('Sorry you should create config file first!'))
819 printNicely(red('No such theme exists.'))
827 h
, w
= os
.popen('stty size', 'r').read().split()
831 usage
+= s
+ 'Hi boss! I\'m ready to serve you right now!\n'
832 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
833 usage
+= s
+ 'You are ' + \
834 light_yellow('already') + ' on your personal stream.\n'
835 usage
+= s
+ 'Any update from Twitter will show up ' + \
836 light_yellow('immediately') + '.\n'
837 usage
+= s
+ 'In addtion, following commands are available right now:\n'
841 usage
+= s
+ grey(u
'\u266A' + ' Discover the world \n')
842 usage
+= s
* 2 + light_green('trend') + ' will show global trending topics. ' + \
843 'You can try ' + light_green('trend US') + ' or ' + \
844 light_green('trend JP Tokyo') + '.\n'
845 usage
+= s
* 2 + light_green('home') + ' will show your timeline. ' + \
846 light_green('home 7') + ' will show 7 tweets.\n'
847 usage
+= s
* 2 + light_green('mentions') + ' will show mentions timeline. ' + \
848 light_green('mentions 7') + ' will show 7 mention tweets.\n'
849 usage
+= s
* 2 + light_green('whois @mdo') + ' will show profile of ' + \
850 magenta('@mdo') + '.\n'
851 usage
+= s
* 2 + light_green('view @mdo') + \
852 ' will show ' + magenta('@mdo') + '\'s home.\n'
853 usage
+= s
* 2 + light_green('s #AKB48') + ' will search for "' + \
854 light_yellow('AKB48') + '" and return 5 newest tweet.\n'
858 usage
+= s
+ grey(u
'\u266A' + ' Tweets \n')
859 usage
+= s
* 2 + light_green('t oops ') + \
860 'will tweet "' + light_yellow('oops') + '" immediately.\n'
862 light_green('rt 12 ') + ' will retweet to tweet with ' + \
863 light_yellow('[id=12]') + '.\n'
865 light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
866 light_yellow('[id=12]') + '.\n'
867 usage
+= s
* 2 + light_green('rep 12 oops') + ' will reply "' + \
868 light_yellow('oops') + '" to tweet with ' + \
869 light_yellow('[id=12]') + '.\n'
871 light_green('fav 12 ') + ' will favorite the tweet with ' + \
872 light_yellow('[id=12]') + '.\n'
874 light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
875 light_yellow('[id=12]') + '.\n'
877 light_green('del 12 ') + ' will delete tweet with ' + \
878 light_yellow('[id=12]') + '.\n'
879 usage
+= s
* 2 + light_green('show image 12') + ' will show image in tweet with ' + \
880 light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
884 usage
+= s
+ grey(u
'\u266A' + ' Direct messages \n')
885 usage
+= s
* 2 + light_green('inbox') + ' will show inbox messages. ' + \
886 light_green('inbox 7') + ' will show newest 7 messages.\n'
887 usage
+= s
* 2 + light_green('sent') + ' will show sent messages. ' + \
888 light_green('sent 7') + ' will show newest 7 messages.\n'
889 usage
+= s
* 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
890 magenta('@dtvd88') + '.\n'
891 usage
+= s
* 2 + light_green('trash 5') + ' will remove message with ' + \
892 light_yellow('[message_id=5]') + '.\n'
894 # Follower and following
896 usage
+= s
+ grey(u
'\u266A' + ' Fiends and followers \n')
898 light_green('ls fl') + \
899 ' will list all followers (people who are following you).\n'
901 light_green('ls fr') + \
902 ' will list all friends (people who you are following).\n'
903 usage
+= s
* 2 + light_green('fl @dtvd88') + ' will follow ' + \
904 magenta('@dtvd88') + '.\n'
905 usage
+= s
* 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
906 magenta('@dtvd88') + '.\n'
907 usage
+= s
* 2 + light_green('mute @dtvd88') + ' will mute ' + \
908 magenta('@dtvd88') + '.\n'
909 usage
+= s
* 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
910 magenta('@dtvd88') + '.\n'
911 usage
+= s
* 2 + light_green('muting') + ' will list muting users.\n'
912 usage
+= s
* 2 + light_green('block @dtvd88') + ' will block ' + \
913 magenta('@dtvd88') + '.\n'
914 usage
+= s
* 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
915 magenta('@dtvd88') + '.\n'
916 usage
+= s
* 2 + light_green('report @dtvd88') + ' will report ' + \
917 magenta('@dtvd88') + ' as a spam account.\n'
921 usage
+= s
+ grey(u
'\u266A' + ' Switching streams \n')
922 usage
+= s
* 2 + light_green('switch public #AKB') + \
923 ' will switch to public stream and follow "' + \
924 light_yellow('AKB') + '" keyword.\n'
925 usage
+= s
* 2 + light_green('switch mine') + \
926 ' will switch to your personal stream.\n'
927 usage
+= s
* 2 + light_green('switch mine -f ') + \
928 ' will prompt to enter the filter.\n'
929 usage
+= s
* 3 + light_yellow('Only nicks') + \
930 ' filter will decide nicks will be INCLUDE ONLY.\n'
931 usage
+= s
* 3 + light_yellow('Ignore nicks') + \
932 ' filter will decide nicks will be EXCLUDE.\n'
933 usage
+= s
* 2 + light_green('switch mine -d') + \
934 ' will use the config\'s ONLY_LIST and IGNORE_LIST.\n'
938 usage
+= s
+ grey(u
'\u266A' + ' Smart shell\n')
939 usage
+= s
* 2 + light_green('111111 * 9 / 7') + ' or any math expression ' + \
940 'will be evaluate by Python interpreter.\n'
941 usage
+= s
* 2 + 'Even ' + light_green('cal') + ' will show the calendar' + \
942 ' for current month.\n'
946 usage
+= s
+ grey(u
'\u266A' + ' Screening \n')
947 usage
+= s
* 2 + light_green('theme') + ' will list available theme.' + \
948 light_green('theme monokai') + ' will apply ' + light_yellow('monokai') + \
949 ' theme immediately.\n'
950 usage
+= s
* 2 + light_green('h') + ' will show this help again.\n'
951 usage
+= s
* 2 + light_green('c') + ' will clear the screen.\n'
952 usage
+= s
* 2 + light_green('q') + ' will quit.\n'
956 usage
+= s
+ '-' * (int(w
) - 4) + '\n'
957 usage
+= s
+ 'Have fun and hang tight! \n'
973 os
.system('rm -rf rainbow.db')
974 os
.kill(g
['stream_pid'], signal
.SIGKILL
)
983 printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
986 printNicely(eval(g
['cmd']))
1037 Listen to user's input
1042 ['public', 'mine'], # switch
1056 ['image'], # show image
1057 ['fl', 'fr'], # list
1071 g
['themes'], # theme
1077 init_interactive_shell(d
)
1082 line
= raw_input(g
['decorated_name'])
1086 cmd
= line
.split()[0]
1090 # Save cmd to global variable and call process
1092 g
['stuff'] = ' '.join(line
.split()[1:])
1094 except Exception as e
:
1096 printNicely(red('OMG something is wrong with Twitter right now.'))
1097 # Not redisplay prefix
1098 if cmd
in ['switch', 't', 'rt', 'rep']:
1104 def stream(domain
, args
, name
='Rainbow Stream'):
1111 c
['USER_DOMAIN']: name
,
1112 c
['PUBLIC_DOMAIN']: args
.track_keywords
,
1113 c
['SITE_DOMAIN']: 'Site Stream',
1116 ascii_art(art_dict
[domain
])
1118 # These arguments are optional:
1120 timeout
=args
.timeout
,
1121 block
=not args
.no_block
,
1122 heartbeat_timeout
=args
.heartbeat_timeout
)
1126 if args
.track_keywords
:
1127 query_args
['track'] = args
.track_keywords
1130 stream
= TwitterStream(
1135 if domain
== c
['USER_DOMAIN']:
1136 tweet_iter
= stream
.user(**query_args
)
1137 elif domain
== c
['SITE_DOMAIN']:
1138 tweet_iter
= stream
.site(**query_args
)
1140 if args
.track_keywords
:
1141 tweet_iter
= stream
.statuses
.filter(**query_args
)
1143 tweet_iter
= stream
.statuses
.sample()
1145 # Iterate over the stream.
1147 for tweet
in tweet_iter
:
1149 printNicely("-- None --")
1150 elif tweet
is Timeout
:
1151 printNicely("-- Timeout --")
1152 elif tweet
is HeartbeatTimeout
:
1153 printNicely("-- Heartbeat Timeout --")
1154 elif tweet
is Hangup
:
1155 printNicely("-- Hangup --")
1156 elif tweet
.get('text'):
1159 iot
=args
.image_on_term
,
1160 keyword
=args
.track_keywords
,
1166 magenta("I'm afraid we have problem with twitter'S maximum connection."))
1167 printNicely(magenta("Let's try again later."))
1174 # Spawn stream process
1175 args
= parse_arguments()
1176 get_decorated_name()
1182 g
['original_name']))
1185 # Start listen process
1189 g
['stream_pid'] = p
.pid
1190 g
['iot'] = args
.image_on_term