Last active
August 29, 2015 14:23
-
-
Save igr-santos/432f9281681d303c5f91 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 time | |
import serial | |
from decouple import config | |
from tweepy import OAuthHandler, StreamListener, Stream | |
DEVICE = '/dev/ttyACM0' | |
BAUD_RATE = 9600 | |
def write(message): | |
try: | |
arduino = serial.Serial(DEVICE, BAUD_RATE, timeout=1) | |
arduino.write(message) | |
read() | |
arduino.close() | |
except serial.SerialException as err: | |
print err | |
def read(): | |
try: | |
arduino = serial.Serial(DEVICE, BAUD_RATE, timeout=1) | |
output = arduino.readline() | |
print 'arduino says: %s' % output | |
arduino.close() | |
except serial.SerialException as err: | |
print err | |
class StdOutListener(StreamListener): | |
def on_status(self, status): | |
print 'Tweet text:' + status.text | |
# write(status.text) | |
return True | |
def on_error(self, status_code): | |
print 'Error code: ' + str(status_code) | |
return True | |
def on_timeout(self): | |
print 'Timeout ...' | |
return True | |
if __name__ == '__main__': | |
listener = StdOutListener() | |
auth = OAuthHandler(config('CONSUMER_KEY'), config('CONSUMER_SECRET')) | |
auth.set_access_token(config('ACCESS_TOKEN'), | |
config('ACCESS_TOKEN_SECRET')) | |
stream = Stream(auth, listener) | |
stream.filter(track=['#twuino', '#pythonmg']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment