Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
221
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.  
  3. import twitter
  4. import serial
  5. import time
  6.  
  7. ##authenticate yourself with twitter
  8. api = twitter.Api(consumer_key='XXXXXXXXXXXX',
  9. consumer_secret='XXXXXXXXXXX', access_token_key='XXXXXXXXXXXX',
  10. access_token_secret='XXXXXXXXXXXXXXXXXXXXXX')
  11.  
  12. ##set to your serial port
  13. ser = serial.Serial('/dev/tty.usbmodem411', 19200)
  14.  
  15. ## check serial port
  16. def checkokay():
  17. ser.flushInput()
  18. time.sleep(3)
  19. line= ser.readline()
  20. time.sleep(3)
  21.  
  22. if line == ' ':
  23. line=ser.readline()
  24. print 'here'
  25. ## Welcome message
  26. print 'Welcome To autokahwa!'
  27. print 'Making kahwa..'
  28. def autokahwa():
  29. status = [ ]
  30. x = 0
  31.  
  32. status = api.GetUserTimeline('X') ##grab latest statuses
  33.  
  34. checkIt = [s.text for s in status] ##put status in an array
  35.  
  36. drip = checkIt[0].split() ##split first tweet into words
  37.  
  38. ## check for match and write to serial if match
  39. if drip[0] == '#autokahwa':
  40. print 'Tweet Recieved, Making Kahwa'
  41. ser.write('1')
  42. elif drip[0] == '#autokahwastop': ##break if done
  43. ser.write('0')
  44. print 'stopped, awaiting instructions.'
  45. else:
  46. ser.write('0')
  47. print 'Awaiting Tweet'
  48.  
  49. while 1:
  50. autokahwa() ## call autokahwa function
  51. time.sleep(15) ## sleep for 15 seconds to avoid rate limiting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement