Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import datetime
- from datetime import date
- from twilio.rest import Client
- from subprocess import call
- print("Garage loop, starting...")
- client = Client('account_sid', 'account_token')
- valid_command = ['o', 'c', 't',]
- valid_numbers = [
- '+12813308004', # Let's let Mike Jones have access
- ]
- processed_messages = {
- str(date.today()): [m.sid for m in client.messages.list(date_sent=date.today())]
- }
- print("Garage loop, listening...")
- while(True):
- today = date.today()
- if str(today) not in processed_messages:
- processed_messages[str(today)] = []
- messages = client.messages.list(date_sent=date.today())
- for message in messages:
- b, f = message.body, message.from_
- if message.sid not in processed_messages[str(today)]:
- processed_messages[str(today)].append(message.sid)
- print("Message [{0}] received from [{1}], processing...".format(b, f))
- if message.body is not None and message.body.lower() in valid_command and message.from_ in valid_numbers:
- print(" [+] authorized [{0}]".format(message.sid))
- call("{your garage wiringPI script to toggle the relay switch")
- else:
- print(" [-] unauthorized [{0}]".format(message.sid))
- else:
- continue
- time.sleep(1)
Add Comment
Please, Sign In to add comment