Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##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
Add Comment
Please, Sign In to add comment