<commit_before>import os
import wsgiref.handlers
import logging

from google.appengine.api import users
from google.appengine.api import memcache
from google.appengine.api.urlfetch import DownloadError
from google.appengine.api.labs import taskqueue
from google.appengine.api.labs.taskqueue import Task
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template

from google.appengine.runtime import apiproxy_errors
import twilio
import bus

ACCOUNT_SID = "<KEY>"
ACCOUNT_TOKEN = "5ec48a82949b90511c78c1967a04998d"
SALT_KEY = '<KEY>'
API_VERSION = '2008-08-01'
CALLER_ID = '6084671603'
#CALLER_ID = '4155992671'

URL_BASE = 'http://7.latest.smsmybus.appspot.com/'
#URL_BASE = 'http://smsmybus.appspot.com/'

class PhoneRequestStartHandler(webapp.RequestHandler):
    
    def post(self):
        self.get()
        
    def get(self):
      # logging.info("The request from Twilio %s" % self.request)
      # validate it is in fact coming from twilio
      if ACCOUNT_SID == self.request.get('AccountSid'):
        logging.debug("PHONE request was confirmed to have come from Twilio.")
      else:
        logging.error("was NOT VALID.  It might have been spoofed!")
        self.response.out.write("Illegal caller")
        return

      # setup the response to get the recording from the caller
      r = twilio.Response()
      g = r.append(twilio.Gather(action=URL_BASE+"phone/listenforbus",
                                 method=twilio.Gather.GET,
                                 timeout=10,
                                 finishOnKey="#"))
      g.append(twilio.Say("Welcome to SMS My Bus!"))
      g.append(twilio.Say("Enter the bus number using the keypad. Press the pound key to submit.", 
                          voice=twilio.Say.MAN,
                          language=twilio.Say.ENGLISH, 
                          loop=1))
      #r.append(twilio.Record("http://smsmybus.appspot.com/listen", twilio.Record.GET, maxLength=120))
      logging.debug("now asking the caller to enter their bus route...")
      self.response.out.write(r)<commit_msg>implemented a quota system for users that abuse the SMS interface<commit_after>import os
import wsgiref.handlers
import logging

from google.appengine.api import users
from google.appengine.api import memcache
from google.appengine.api.urlfetch import DownloadError
from google.appengine.api.labs import taskqueue
from google.appengine.api.labs.taskqueue import Task
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template

from google.appengine.runtime import apiproxy_errors
import twilio
import bus

ACCOUNT_SID = "<KEY>"
ACCOUNT_TOKEN = "5ec48a82949b90511c78c1967a04998d"
SALT_KEY = '<KEY>'
API_VERSION = '2008-08-01'
CALLER_ID = '6084671603'
#CALLER_ID = '4155992671'

#URL_BASE = 'http://7.latest.smsmybus.appspot.com/'
URL_BASE = 'http://smsmybus.appspot.com/'

class PhoneRequestStartHandler(webapp.RequestHandler):
    
    def post(self):
        self.get()
        
    def get(self):
      # logging.info("The request from Twilio %s" % self.request)
      # validate it is in fact coming from twilio
      if ACCOUNT_SID == self.request.get('AccountSid'):
        logging.debug("PHONE request was confirmed to have come from Twilio.")
      else:
        logging.error("was NOT VALID.  It might have been spoofed!")
        self.response.out.write("Illegal caller")
        return

      # setup the response to get the recording from the caller
      r = twilio.Response()
      g = r.append(twilio.Gather(action=URL_BASE+"phone/listenforbus",
                                 method=twilio.Gather.GET,
                                 timeout=10,
                                 finishOnKey="#"))
      g.append(twilio.Say("Welcome to SMS My Bus!"))
      g.append(twilio.Say("Enter the bus number using the keypad. Press the pound key to submit.", 
                          voice=twilio.Say.MAN,
                          language=twilio.Say.ENGLISH, 
                          loop=1))
      #r.append(twilio.Record("http://smsmybus.appspot.com/listen", twilio.Record.GET, maxLength=120))
      logging.debug("now asking the caller to enter their bus route...")
      self.response.out.write(r)
{'fraction_non_alphanumeric': 0.10023201856148492, 'fraction_numerical': 0.027378190255220418, 'mean_word_length': 2.7131782945736433, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3759747', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1292, 'n_words': 325}