Last active
April 6, 2017 08:21
-
-
Save unicore32/5eba042eda3ad746e773 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import serial | |
# 各自適当なデバイスファイルに修正してください。 | |
printer = serial.Serial('/dev/tty.SM1-21-SerialPortDevB', 115200) | |
from tweepy.streaming import StreamListener, Stream | |
from tweepy.auth import OAuthHandler | |
from tweepy.api import API | |
from datetime import timedelta | |
def get_oauth(): | |
consumer_key = '' | |
consumer_secret = '' | |
access_key = '' | |
access_secret = '' | |
auth = OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
return auth | |
class CustomStreamListener(StreamListener): | |
def on_status(self, status): | |
status.created_at += timedelta(hours=9) | |
printer.write(u"{text}".format(text=status.text).encode('shift-jis', 'replace') + '\n') | |
printer.write(u"{name}({screen})\n{time}\n".format( | |
name=status.author.name, screen=status.author.screen_name, | |
time=status.created_at).encode('shift-jis', 'replace')) | |
printer.write('-' * 32 + '\n') | |
if __name__ == '__main__': | |
printer.write('\x1c\x26') # Enable Full-Width | |
printer.write('\x1c\x43\x01') # Enable Shift JIS | |
auth = get_oauth() | |
stream = Stream(auth, CustomStreamListener(), secure=True) | |
stream.userstream() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment