Skip to content

Instantly share code, notes, and snippets.

@igr-santos
Last active August 29, 2015 14:23
Show Gist options
  • Save igr-santos/432f9281681d303c5f91 to your computer and use it in GitHub Desktop.
Save igr-santos/432f9281681d303c5f91 to your computer and use it in GitHub Desktop.
#!/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