Ejemplo n.º 1
0
    def post (self):
        json = self.request.body
        logging.info ("json: %s" % json)
        tropo = tropo.Tropo()
        result = tropo.Result(json);
        zip = result.getValue()
        google_weather_url = "%s?weather=%s&hl=en" % (GOOGLE_WEATHER_API_URL, zip)
        resp = urlfetch.fetch(google_weather_url)

        logging.info ("weather url: %s " % google_weather_url)
        if (resp.status_code == 200):
            xml = resp.content
            logging.info ("weather xml: %s " % xml)
            doc = ElementTree.fromstring(xml)            
            logging.info ("doc: %s " % doc)
            condition = doc.find("weather/current_conditions/condition").attrib['data']
            temp_f  = doc.find("weather/current_conditions/temp_f").attrib['data']
            wind_condition = doc.find("weather/current_conditions/wind_condition").attrib['data']
            city = doc.find("weather/forecast_information/city").attrib['data']
            logging.info ("condition: %s temp_f: %s wind_condition: %s city: %s" % (condition, temp_f, wind_condition, city))
            tropo = tropo.Tropo()
            # condition: Partly Cloudy temp_f: 73 wind_condition: Wind: NW at 10 mph city: Portsmouth, NH
            temp = "%s degrees" % temp_f
            wind = self.english_expand (wind_condition)
            tropo.say("Current city is %s . Weather conditions are %s. Temperature is %s. Winds are %s ." % (city, condition, temp, wind))        
            json = tropo.RenderJson()

            self.response.out.write(json)
Ejemplo n.º 2
0
 def post(self):
     tropo = tropo.Tropo()
     tropo.call(MY_PHONE, channel='TEXT', network='SMS', answerOnMedia='True')
     tropo.say ("Wish you were here")
     json = tropo.RenderJson()
     logging.info ("Json result: %s " % json)
     self.response.out.write(json)
Ejemplo n.º 3
0
    def post(self):
        if (1):
            tropo = tropo.Tropo()
            tropo.say ("Welcome to the Tropo web API demo")

            request = "Please press"
            choices_string = ""
            choices_counter = 1
            for key in sorted(DEMOS.iterkeys()):
                if (len(choices_string) > 0):
                    choices_string = "%s,%s" % (choices_string, choices_counter)
                else:
                    choices_string = "%s" % (choices_counter)
                demo_name = DEMOS[key][0]
                demo = DEMOS[key][1]
                request = "%s %s for %s," % (request, key, demo_name)
                choices_counter += 1
            choices = tropo.Choices(choices_string).obj

            tropo.ask(choices, say=request, attempts=3, bargein=True, name="zip", timeout=5, voice="dave")

            tropo.on(event="continue", 
                     next="/demo_continue.py",
                     say="Please hold.")

            tropo.on(event="error",
                     next="/demo_continue.py",
                     say="An error occurred.")

            json = tropo.RenderJson()
            logging.info ("Json result: %s " % json)
            self.response.out.write(json)
Ejemplo n.º 4
0
def HelloWorld(handler, tropo):
    """
    This is the traditional "Hello, World" function. The idiom is used throughout the API. We construct a Tropo object, and then flesh out that object by calling "action" functions (in this case, tropo.say). Then call tropo.Render, which translates the Tropo object into JSON format. Finally, we write the JSON object to the standard output, so that it will get POSTed back to the API.
    """
    tropo.say (["Hello, World", "How ya doing?"])
    json = tropo.RenderJson()
    logging.info ("HelloWorld json: %s" % json)
    handler.response.out.write(json)
Ejemplo n.º 5
0
def HelloWorld(handler, tropo):
    """
    This is the traditional "Hello, World" function. The idiom is used throughout the API. We construct a Tropo object, and then flesh out that object by calling "action" functions (in this case, tropo.say). Then call tropo.Render, which translates the Tropo object into JSON format. Finally, we write the JSON object to the standard output, so that it will get POSTed back to the API.
    """
    tropo.say(["Hello, World", "How ya doing?"])
    json = tropo.RenderJson()
    logging.info("HelloWorld json: %s" % json)
    handler.response.out.write(json)
Ejemplo n.º 6
0
def RedirectDemo(handler, tropo):
    """
    Demonstration of redirecting to another number.
    """
    tropo.say ("One moment please.")
    tropo.redirect(MY_PHONE)
    json = tropo.RenderJson()
    logging.info ("RedirectDemo json: %s" % json)
    handler.response.out.write(json)
Ejemplo n.º 7
0
def RedirectDemo(handler, tropo):
    """
    Demonstration of redirecting to another number.
    """
    tropo.say("One moment please.")
    tropo.redirect(MY_PHONE)
    json = tropo.RenderJson()
    logging.info("RedirectDemo json: %s" % json)
    handler.response.out.write(json)
Ejemplo n.º 8
0
 def post(self):
     tropo = tropo.Tropo()
     tropo.call(MY_PHONE,
                channel='TEXT',
                network='SMS',
                answerOnMedia='True')
     tropo.say("Wish you were here")
     json = tropo.RenderJson()
     logging.info("Json result: %s " % json)
     self.response.out.write(json)
Ejemplo n.º 9
0
def TransferDemo(handler, tropo):
    """
    Demonstration of transfering to another number
    """
    # http://www.s3fm.com/
    tropo.say ("One moment please.")
    tropo.transfer(MY_PHONE)
    tropo.say("Hi. I am a robot")
    json = tropo.RenderJson()
    logging.info ("TransferDemo json: %s" % json)
    handler.response.out.write(json)
Ejemplo n.º 10
0
def TransferDemo(handler, tropo):
    """
    Demonstration of transfering to another number
    """
    # http://www.s3fm.com/
    tropo.say("One moment please.")
    tropo.transfer(MY_PHONE)
    tropo.say("Hi. I am a robot")
    json = tropo.RenderJson()
    logging.info("TransferDemo json: %s" % json)
    handler.response.out.write(json)
Ejemplo n.º 11
0
def RecordHelloWorld(handler, tropo):
    """
    Demonstration of recording a message.
    """
    # http://www.s3fm.com/
    url = "/receive_recording.py"
    tropo.startRecording(url)
    tropo.say ("Hello, World.")
    tropo.stopRecording()
    json = tropo.RenderJson()
    logging.info ("RecordHelloWorld json: %s" % json)
    handler.response.out.write(json)
Ejemplo n.º 12
0
def RecordHelloWorld(handler, tropo):
    """
    Demonstration of recording a message.
    """
    # http://www.s3fm.com/
    url = "/receive_recording.py"
    tropo.startRecording(url)
    tropo.say("Hello, World.")
    tropo.stopRecording()
    json = tropo.RenderJson()
    logging.info("RecordHelloWorld json: %s" % json)
    handler.response.out.write(json)
Ejemplo n.º 13
0
    def post(self):
        if (1):
            tropo = tropo.Tropo()
            tropo.say("Welcome to the Tropo web API demo")

            request = "Please press"
            choices_string = ""
            choices_counter = 1
            for key in sorted(DEMOS.iterkeys()):
                if (len(choices_string) > 0):
                    choices_string = "%s,%s" % (choices_string,
                                                choices_counter)
                else:
                    choices_string = "%s" % (choices_counter)
                demo_name = DEMOS[key][0]
                demo = DEMOS[key][1]
                request = "%s %s for %s," % (request, key, demo_name)
                choices_counter += 1
            choices = tropo.Choices(choices_string).obj

            tropo.ask(choices,
                      say=request,
                      attempts=3,
                      bargein=True,
                      name="zip",
                      timeout=5,
                      voice="dave")

            tropo.on(event="continue",
                     next="/demo_continue.py",
                     say="Please hold.")

            tropo.on(event="error",
                     next="/demo_continue.py",
                     say="An error occurred.")

            json = tropo.RenderJson()
            logging.info("Json result: %s " % json)
            self.response.out.write(json)
Ejemplo n.º 14
0
    def post(self):
        json = self.request.body
        logging.info("json: %s" % json)
        tropo = tropo.Tropo()
        result = tropo.Result(json)
        zip = result.getValue()
        google_weather_url = "%s?weather=%s&hl=en" % (GOOGLE_WEATHER_API_URL,
                                                      zip)
        resp = urlfetch.fetch(google_weather_url)

        logging.info("weather url: %s " % google_weather_url)
        if (resp.status_code == 200):
            xml = resp.content
            logging.info("weather xml: %s " % xml)
            doc = ElementTree.fromstring(xml)
            logging.info("doc: %s " % doc)
            condition = doc.find(
                "weather/current_conditions/condition").attrib['data']
            temp_f = doc.find(
                "weather/current_conditions/temp_f").attrib['data']
            wind_condition = doc.find(
                "weather/current_conditions/wind_condition").attrib['data']
            city = doc.find("weather/forecast_information/city").attrib['data']
            logging.info(
                "condition: %s temp_f: %s wind_condition: %s city: %s" %
                (condition, temp_f, wind_condition, city))
            tropo = tropo.Tropo()
            # condition: Partly Cloudy temp_f: 73 wind_condition: Wind: NW at 10 mph city: Portsmouth, NH
            temp = "%s degrees" % temp_f
            wind = self.english_expand(wind_condition)
            tropo.say(
                "Current city is %s . Weather conditions are %s. Temperature is %s. Winds are %s ."
                % (city, condition, temp, wind))
            json = tropo.RenderJson()

            self.response.out.write(json)
Ejemplo n.º 15
0
def ConferenceDemo(handler, tropo):
    tropo.say ("Have some of your friends launch this demo. You'll be on the world's simplest conference call. Now, for a little music, while we wait for the others.")
    tropo.conference("partyline", terminator="#", name="Family Meeting")
    tropo.say("http://denalidomain.com/music/keepers/Fontella%20Bass%20This%20Little%20Light%20Of%20Mine.mp3")
#    tropo.call(MY_PHONE)

#    tropo.call(THEIR_PHONE)
    tropo.say ("How do you like the conference so far?")
    json = tropo.RenderJson()
    logging.info ("CallDemo json: %s " % json)
    handler.response.out.write(json)
Ejemplo n.º 16
0
def ConferenceDemo(handler, tropo):
    tropo.say(
        "Have some of your friends launch this demo. You'll be on the world's simplest conference call. Now, for a little music, while we wait for the others."
    )
    tropo.conference("partyline", terminator="#", name="Family Meeting")
    tropo.say(
        "http://denalidomain.com/music/keepers/Fontella%20Bass%20This%20Little%20Light%20Of%20Mine.mp3"
    )
    #    tropo.call(MY_PHONE)

    #    tropo.call(THEIR_PHONE)
    tropo.say("How do you like the conference so far?")
    json = tropo.RenderJson()
    logging.info("CallDemo json: %s " % json)
    handler.response.out.write(json)