Guest User

Untitled

a guest
Jan 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import time
  2. import datetime
  3.  
  4. from datetime import date
  5. from twilio.rest import Client
  6. from subprocess import call
  7.  
  8. print("Garage loop, starting...")
  9. client = Client('account_sid', 'account_token')
  10.  
  11. valid_command = ['o', 'c', 't',]
  12. valid_numbers = [
  13. '+12813308004', # Let's let Mike Jones have access
  14. ]
  15.  
  16. processed_messages = {
  17. str(date.today()): [m.sid for m in client.messages.list(date_sent=date.today())]
  18. }
  19.  
  20. print("Garage loop, listening...")
  21.  
  22. while(True):
  23. today = date.today()
  24.  
  25. if str(today) not in processed_messages:
  26. processed_messages[str(today)] = []
  27.  
  28. messages = client.messages.list(date_sent=date.today())
  29.  
  30. for message in messages:
  31. b, f = message.body, message.from_
  32.  
  33. if message.sid not in processed_messages[str(today)]:
  34. processed_messages[str(today)].append(message.sid)
  35.  
  36. print("Message [{0}] received from [{1}], processing...".format(b, f))
  37.  
  38. if message.body is not None and message.body.lower() in valid_command and message.from_ in valid_numbers:
  39. print(" [+] authorized [{0}]".format(message.sid))
  40. call("{your garage wiringPI script to toggle the relay switch")
  41. else:
  42. print(" [-] unauthorized [{0}]".format(message.sid))
  43. else:
  44. continue
  45.  
  46. time.sleep(1)
Add Comment
Please, Sign In to add comment