Ejemplo n.º 1
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('category')
        parser.add_argument('text')
        args = parser.parse_args()

        if args['category'] == 'shopping':
            facebook = Facebook(
                'CAAGyweZCX3VUBAFUgJTDxFBVCUG1vux1mF5j1BfTUUGWTDqnc0VzRPn1hg0ZCtmv1S9StPpi5iSF4GGqD4YsMVA3f0oEf3YRG7hLDXSPxx0OvTI5ZA9MbiUCjlHy7lBa83kjZAVO52Py1u6nQFIyZBxwn2P86ITYYjaK2D0tAraFdqG8csbuoLDMUPef3eN9bDVJXX78s7JEXB82WBpa7')
            likes = facebook.get_likes(args['text'])
            print likes
            amazon = Amazon()

            products = {}

            for like in likes:
                items = amazon.search_for(like)
                if len(items) == 2:
                    products[like] = items[1]

            return products
Ejemplo n.º 2
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('text')
        parser.add_argument('access_token')
        args = parser.parse_args()

        if args['text'].lower() in self.cache:
            return self.cache[args['text'].lower()]

        data = parse(args['text'])

        response = {}

        if data['intent'] == 'birthdays':
            facebook = Facebook(args['access_token'])
            likes = facebook.get_likes(data['entities']['contact'][0]['value'])

            amazon = Amazon()

            products = {}

            for like in likes:
                items = amazon.search_for(like)
                products[like] = items
                print items

            response = {
                'products': products,
                'name': data['entities']['contact'][0]['value'],
            }



        elif data['intent'] == 'travel':
            response = {'travel': {}}

            try:
                rome2rio = get_rome_rio('Menlo Park', data['entities']['location'][0]['value'])
            except:
                print "Error"
                return {'error': True};
            response['travel']['plan'] = rome2rio[0][0]
            response['travel']['places'] = rome2rio[1]

            pos = rome2rio[1][1]['pos'].split(',')
            start = rome2rio[1][0]['pos'].split(',')


            if response['travel']['plan']['distance'] > 200:
                airbnb = AirBnB()
                response['accomodation'] = airbnb.get_accomodation(pos[0], pos[1])

                cars = CarRental()
                response['rental'] = cars.get_cars(start[0], start[1])

            else:
                uber = Uber()


                response['taxi'] = uber.get_estimate(start[0], start[1], pos[0], pos[1])





        elif data['intent'] == 'restaurant_booking':
            response = {}
            try:
                response['restaurants'] = get_restaurants(data['entities'], None, None, None)
            except:
                print "Error"
                return {'error': True};


        elif data['intent'] == 'flights':
            response = {}
            flights = InspiredFlights()

            response['flights'] = flights.where_can_i_fly(data['entities']['location'][0]['value'],
                                                          data['entities']['amount_of_money'][0]['value'])


        response['type'] = data['intent']

        self.cache[args['text'].lower()] = response
        self.save_cache()
        return response