Example #1
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()
Example #2
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)
Example #3
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
Example #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)
Example #5
0
    def POST(self, lat, lon, page):

        lat = float(lat)
        lon = float(lon)
        page = int(page)
        body = web.ctx.env['wsgi.input'].read()
        print body
        result = tropo.Result(body)
        choice = int(result.getValue())
        if choice < 4:
            nearby = search_results.get_results(lat, lon, page)
            print nearby
            response = self.get_detail(nearby[choice-1])
        else:
            response = self.prompt_results(lat, lon, page+1)

        return response
Example #6
0
 def dispatch(self, request, *args, **kwargs):
     try:
         session_engine = import_module(settings.SESSION_ENGINE)
         tropo_session = tropo.Session(request.raw_post_data).dict
         session_key = tropo_session.get('id', None)
         if session_key:
             self.session = session_engine.SessionStore(session_key)
             self.session.save(must_create=True)
             self.session.update(tropo_session)
             self.session.set_expiry(60 * 5)
             self.session.save()
     except:
         try:
             self.result = tropo.Result(request.raw_post_data)
             session_engine = import_module(settings.SESSION_ENGINE)
             actions = getattr(self.result, '_actions', [])
             if (type(actions) is dict):
                 actions = [actions]
             for action in actions:
                 kwargs[str(action['name'])] = action
             self.session = session_engine.SessionStore(self.result._sessionId)
         except:
             pass
     return super(TropoView, self).dispatch(request, *args, **kwargs)