Beispiel #1
0
    def post(self):
        t = tropo.Tropo()
        t.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)

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

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

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

        json = t.RenderJson()
        logging.info("Json result: %s " % json)
        self.response.out.write(json)
Beispiel #2
0
 def post(self):
     t = tropo.Tropo()
     t.call(MY_PHONE, channel='TEXT', network='SMS', answerOnMedia='True')
     t.say("Wish you were here")
     json = t.RenderJson()
     logging.info("Json result: %s " % json)
     self.response.out.write(json)
Beispiel #3
0
    def POST(self):

        print "In getlocation"

        t = tropo.Tropo()
        body = web.ctx.env['wsgi.input'].read()
        print body
        result = tropo.Result(body)
        text = result.getValue().lower()

        option_names = {'food': "food",
                        'shelter': "shelter",
                        'health': "health services"}
        if text in ["food", "shelter", "health"]:
            option = text
            ask_txt = "Searching for %s. What is your location?" %\
                      option_names[option]
            t.ask(say=ask_txt, choices="[ANY]", timeout=30)
            t.on(event="continue", next="/search/%s" % option)
        else:
            t.say("Welcome to sheltr. For food, reply with FOOD. " +\
                  "For shelter, reply with SHELTER. For health services, " +\
                  "reply with HEALTH.")

        return t.RenderJson()
Beispiel #4
0
    def post(self):
        json = self.request.body
        logging.info("json: %s" % json)

        uri = self.request.get('uri')
        logging.info("uri: %s" % uri)

        t = tropo.Tropo()

        if (uri == "error"):
            t.say("Oops. There was some kind of error")
            json = t.RenderJson()
            self.response.out.write(json)
            return

        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))
            t = 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)
            t.say(
                "Current city is %s . Weather conditions are %s. Temperature is %s. %s ."
                % (city, condition, temp, wind))
            json = t.RenderJson()

            self.response.out.write(json)
Beispiel #5
0
    def prompt_results(cls, lat, lon, page):

        t = tropo.Tropo()
        real_page = page - 1
        results = search_results.get_results(lat, lon, page)
        result_strs = ["%d. %s (%.1fmi)" % (num+1, r['name'], r['dist'])
                       for num, r in enumerate(results)]
        result_str = "Results: %s 4. More" % " ".join(result_strs)
        t.ask(say=result_str, choices="1,2,3,4", timeout=30, attempts=2)
        next = "/results/%f/%f/%d" % (lat, lon, page)
        t.on(event="continue", next=next)

        return t.RenderJson()
Beispiel #6
0
    def POST(self, option):

        t = tropo.Tropo()
        body = web.ctx.env['wsgi.input'].read()
        print body
        result = tropo.Result(body)
        location = result.getValue()

        (lat, lon) = geocode(location)

        print lat, lon

        return search_results.prompt_results(lat, lon, 1)
Beispiel #7
0
    def post(self):
        json = self.request.body
        logging.info("json: %s" % json)
        t = tropo.Tropo()
        result = tropo.Result(json)
        choice = result.getValue()
        logging.info("Choice of demo is: %s" % choice)

        for key in DEMOS:
            if (choice == key):
                demo_name = DEMOS[key][0]
                demo = DEMOS[key][1]
                demo(self, t)
                break
Beispiel #8
0
    def POST(self):
        t = tropo.Tropo()
        t.ask(say="", choices="[ANY]")
        t.on(event='continue', next='/getlocation')

        return t.RenderJson()
Beispiel #9
0
    def get_detail(self, obj):

        t = tropo.Tropo()
        t.say("Info for: %s" % obj['name'])

        return t.RenderJson()