Skip to content

Instantly share code, notes, and snippets.

@spencersugarman
Created May 31, 2012 02:00
Show Gist options
  • Save spencersugarman/2840374 to your computer and use it in GitHub Desktop.
Save spencersugarman/2840374 to your computer and use it in GitHub Desktop.
serial2twitter script for Cookieduino project
##Import libraries
import time
import serial
import tweepy
auth = tweepy.OAuthHandler('secret', 'secret')
auth.set_access_token('sauce', 'sauce')
api = tweepy.API(auth)
##Configure serial port
arduino = serial.Serial('/dev/tty.usbmodem1d11', 9600, timeout=1)
##Instantiate variables
current = None
previous = None
while 1: ##Infinite Loop
line = arduino.read(24) ##Wait for new line to come across Serial
if 'Low' in line:
print 'Low'
if 'Medium' in previous or 'High' in previous:
current = '<<cookies eaten>> Warning: cookie levels are running dangerously low, cap\'n'
else:
current = '<<cookies added>> Ah...sweet, sweet cookies...'
elif 'Medium' in line:
print 'Medium'
current = '<<cookies added>> These cookies are relevant to my interests.'
elif 'High' in line:
print 'High'
current = '<<cookies added>> SO MANY COOKIES SO LITTLE TIME!'
else:
print 'None'
if 'Low' in previous or 'Medium' in previous or 'High' in previous:
current = 'Oh the humanity...the cookie jar is empty! D:'
if current != previous:
previous = current
try:
api.update_status(current) ##Post message to Twitter
except tweepy.error.TweepError:
continue
del current ##Clear status
time.sleep(1) ##Wait 1 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment