Skip to content

Instantly share code, notes, and snippets.

@gtracy
Created August 2, 2010 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtracy/504164 to your computer and use it in GitHub Desktop.
Save gtracy/504164 to your computer and use it in GitHub Desktop.
class MainHandler(webapp.RequestHandler):
def post(self):
# this handler is intended for admin use only
# only accept calls from my own phone
caller = self.request.get('From')
if caller != '608XXXXXXX':
logging.error('illegal caller %s with message %s' % (caller,self.request.get('Body')))
return
# validate it is in fact coming from twilio
if ACCOUNT_SID == self.request.get('AccountSid'):
logging.info("was confirmed to have come from Twilio (%s)." % caller)
else:
logging.info("was NOT VALID. It might have been spoofed (%s)!" % caller)
return
# determine the command from the message
body = self.request.get('Body')
if body is None:
logging.error('empty command!?')
return
command = body.split()
logging.info('processing new command %s from message %s' % (command[0],body))
if command[0].lower() == 'help':
# setup the response SMS
smsBody = "disable, enable, event <#>, get, add <name> <name> <number>"
elif command[0].lower() == 'disable':
setService(False)
smsBody = "turned service off!"
elif command[0].lower() == 'enable':
setService(True)
smsBody = "turned service on!"
elif command[0].lower() == 'add':
addUser(body)
smsBody = "added athlete %s" % command[1]
elif command[0].lower() == 'event':
setEvent(command[1])
smsBody = "set event to %s" % command[1]
elif command[0].lower() == 'get':
smsBody = "current event is %s" % memcache.get('eventNumber')
else:
smsBody = "error... unsupported command [%s]" % command[0]
logging.debug("responding to query with %s" % smsBody)
r = twilio.Response()
r.append(twilio.Sms(smsBody))
self.response.out.write(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment