Guest User

Untitled

a guest
Oct 15th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. ##Import libraries
  2. import time
  3. import serial
  4. import tweepy
  5.  
  6. auth = tweepy.OAuthHandler('secret', 'secret')
  7. auth.set_access_token('sauce', 'sauce')
  8. api = tweepy.API(auth)
  9.  
  10. ##Configure serial port
  11. arduino = serial.Serial('/dev/tty.usbmodem1d11', 9600, timeout=1)
  12.  
  13. ##Instantiate variables
  14. current = None
  15. previous = None
  16.  
  17. while 1: ##Infinite Loop
  18. line = arduino.read(24) ##Wait for new line to come across Serial
  19. if 'Low' in line:
  20. print 'Low'
  21. if 'Medium' in previous or 'High' in previous:
  22. current = '<<cookies eaten>> Warning: cookie levels are running dangerously low, cap\'n'
  23. else:
  24. current = '<<cookies added>> Ah...sweet, sweet cookies...'
  25. elif 'Medium' in line:
  26. print 'Medium'
  27. current = '<<cookies added>> These cookies are relevant to my interests.'
  28. elif 'High' in line:
  29. print 'High'
  30. current = '<<cookies added>> SO MANY COOKIES SO LITTLE TIME!'
  31. else:
  32. print 'None'
  33. if 'Low' in previous or 'Medium' in previous or 'High' in previous:
  34. current = 'Oh the humanity...the cookie jar is empty! D:'
  35. if current != previous:
  36. previous = current
  37. try:
  38. api.update_status(current) ##Post message to Twitter
  39. except tweepy.error.TweepError:
  40. continue
  41. del current ##Clear status
  42. time.sleep(1) ##Wait 1 seconds
Add Comment
Please, Sign In to add comment