Browse files

First attempt at an answer handler

  • Loading branch information...
1 parent 5f94132 commit 7b48e2a62340a2a98258e7ce41d4dbfb78ff2db6 @pedantic-git pedantic-git committed Aug 7, 2011
Showing with 19 additions and 2 deletions.
  1. +17 −1 src/SMS.py
  2. +2 −1 src/sms-hunt.py
View
18 src/SMS.py
@@ -6,6 +6,7 @@
import base64
from xml.etree import ElementTree
import logging
+from Hunt import *
def send(recipient, message):
"""Send this message to the specified recipient. Returns an HTTP
@@ -20,7 +21,22 @@ def send(recipient, message):
xml = """<?xml version='1.0' encoding='UTF-8'?><messages><accountreference>%s</accountreference><message><to>%s</to><body>%s</body></message></messages>""" % (account_settings['account'], recipient, message)
result = urlfetch.fetch(url=url, method=urlfetch.POST, payload=xml, headers={'Content-Type' : 'text/xml', 'Authorization' : "Basic %s" % (encoded_username)})
return result.status_code
-
+
+class AnswerHandler(webapp.RequestHandler):
+
+ def post(self):
+ body = self.request.body
+ m = re.search('<MessageText>(.*?)</MessageText>')
+ msg = m.group(1)
+ m = re.search('<From>44(\d+)</From>')
+ number_without_zero = m.group(1)
+
+ if msg and number_without_zero:
+ Team.deliver("0%s" % number_without_zero, msg)
+ self.response.out.write("Delivered to app!")
+ else:
+ self.response.set_status(500)
+ self.response.out.write("WTF Esendex?")
class SendSMS(webapp.RequestHandler):
View
3 src/sms-hunt.py
@@ -4,7 +4,7 @@
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
-from SMS import SendSMS, PollSMS
+from SMS import SendSMS, PollSMS, AnswerHandler
from controller import Index, CreateHunt, ShowHunt, Clues, Teams
import utils
import logging
@@ -17,6 +17,7 @@
('/hunt/(.*)/clues', Clues),
('/hunt/(.*)/teams', Teams),
('/hunt/(.*)', ShowHunt),
+ ('/answer-handler', AnswerHandler),
],
debug=True)

0 comments on commit 7b48e2a

Please sign in to comment.