def showTL(api, read_id): try: tl = api.list_timeline('haya14busa', 'it', count=10, since_id = read_id) tl.reverse() for status in tl: status.created_at += timedelta(hours=9) # add 9 hours for Japanese time print u'---{name}/@{screen}---\n {text}\nvia {src} {created}'.format( name = status.author.name, screen = status.author.screen_name, text = status.text, src = status.source, created = status.created_at) read_text = str_replace(status.text.encode('utf_8')) read_text = romaji2katakana(read_text) # print read_text call(['SayKotoeri -s "-s 120" "{text}" >/dev/null 2>&1'.format(text=read_text)], shell=True) # call(['say -v "kyoko" "{text}"'.format(text=read_text)], shell=False) # Kyoko # call(['say "{text}"'.format(text=read_text)], shell=False) # for English else: global lastSinceId lastSinceId = tl[-1].id except Exception, e: time.sleep(10) pass
def on_status(self, status): try: status.created_at += timedelta(hours=9) # add 9 hours for Japanese time if hasattr(status, 'retweeted_status'): name = status.retweeted_status.author.name screen = status.retweeted_status.author.screen_name text = status.retweeted_status.text src = status.retweeted_status.source created = status.retweeted_status.created_at rtby = status.author.screen_name print RT_TEMPLATE.format( name=name, screen=screen, text=text, src=src, created=created, rtby=rtby) else: name = status.author.name screen = status.author.screen_name text = status.text src = status.source created = status.created_at print TEMPLATE.format( name=name, screen=screen, text=text, src=src, created=created) read_text = str_replace(text.encode('utf-8')) read_text = romaji2katakana(read_text) cmd = 'SayKotoeri -s "-s 120" "{text}" >/dev/null 2>&1'.format(text=read_text) # cmd = 'SayKotoeri2 -p aq_rb2 -b 80 -s 120 "{text}" >/dev/null 2>&1'.format(text=read_text) try: call(cmd, shell=True) except: print "SayKotoeri Couldn't read aloud" except Exception, e: print >> sys.stderr, 'Encountered Exception:', e pass