Beispiel #1
0
    def post(self, business_id):

        business = BusinessModel.find_by_id(business_id)

        if business:
            data = Event.parser.parse_args()
        else:
            return {'message': 'business does not exist'}, 404

        if EventsModel.find_by_name(data['event_name']):
            return {
                'message':
                "An event with name '{}' already exists.".format(
                    data['event_name'])
            }, 400

        event = EventsModel(data['event_name'], data['name'], business_id,
                            data['description'], data['address'],
                            data['cityname'], data['postcode'],
                            data['event_type'], data['date'],
                            data['doorsopen'], data['doorsclose'],
                            data['minage'], data['entryprice'], data['url'],
                            data['longitude'], data['latitude'])

        try:
            event.save_to_db()
        except:
            return {"message": "An error occurred inserting the event."}, 500

        return event.json(), 201
Beispiel #2
0
        def delete(self, username):
            business = BusinessModel.find_by_username(username)

            if business:
                business.delete_from_db()
                return {'message': "Business deleted."}

            return {'message': 'Business not found.'}, 404
Beispiel #3
0
    def patch(self, business_name):
        data = ChangeBusUsername.parser.parse_args()

        business = BusinessModel.find_by_business_name(business_name)

        if business:
            business.username = data['username']

        business.save_to_db()
        return {"message": "Username successfully updated"}, 201
Beispiel #4
0
    def patch(self, business_name):
        data = ChangeBusPassword.parser.parse_args()

        business = BusinessModel.find_by_business_name(business_name)

        if business:
            business.password = sha256_crypt.hash(data['password'])

        business.save_to_db()

        return {"message": "Password successfully updated."}, 201
Beispiel #5
0
    def post(self):
        data = Done.parser.parse_args()
        liked_yelp_id_list = data['liked_yelp_id'].split()
        liked_photo_id_list = data['liked_photo_id'].split()
        if len(liked_photo_id_list) != len(liked_yelp_id_list):
            return {"message": "liked_photo_id and liked_yelp_id lengths must match!"}, 400
        result = []

        for single_yelp_id, single_photo_id in zip(liked_yelp_id_list, liked_photo_id_list):
            result.append(BusinessModel.find_by_yelp_id(single_yelp_id).json(single_photo_id))

        return result, 200
Beispiel #6
0
    def patch(self, business_name):
        data = ChangeBusDetails.parser.parse_args()

        business = BusinessModel.find_by_business_name(business_name)

        if business:
            business.email = data['email']
            business.business_name = data['business_name']
            business.address = data['address']
            business.description = data['description']

        business.save_to_db()
        return {"message": "Business details successfully updated"}, 201
Beispiel #7
0
    def post(cls):
        data = cls.parser.parse_args()

        business = BusinessModel.find_by_username(data['username'])
        
        orig = data['password']

        if business and sha256_crypt.verify(orig, business.password):
            access_token = create_access_token(identity=business.id, fresh=True)
            refresh_token = create_refresh_token(business.id)
            return {
                "details": business.json(),
                'message': 'Business User logged in',
                'access_token': access_token,
                'refresh_token': refresh_token
            }, 200
        
        return {'message': 'Invalid credentials'}, 401
Beispiel #8
0
    def post(self):
        data = BusinessRegister.parser.parse_args()

        if BusinessModel.find_by_business_name(data['business_name']):
            return {'message': "A business with name '{}' already exists.".format(data['business_name'])}, 400 #

        business = BusinessModel(data['username'], sha256_crypt.hash(data['password']), data['email'], data['business_name'],
                         data['address'], data['description'], data['url'], data['avatar'])
        business.save_to_db()
            # except:
            #     return {"message": "An error occurred creating the store."}, 500

        return business.json(), 201
Beispiel #9
0
    def post(self):
        """
        receives longitude, lattitude, price, and range
        needs to make call to yelp.
        save each business to the db
        scrape and save
        return objects in form url, name
        """
        data = Start.parser.parse_args()
        if data["low_price"] < 1 or data["low_price"] > 4:
            return {"message": "price should be in range of 1 to 4"}, 400
        if data["high_price"] < 1 or data["high_price"] > 4:
            return {"message": "price should be in range of 1 to 4"}, 400
        price_range = ''
        for price in range(data['low_price'], data['high_price']):
            price_range += (str(price) + ', ')
        price_range += str(data['high_price'])
        url_params = {
            'term': 'restaurants',
            'latitude': data['lat'],
            'longitude': data['long'],
            'price': price_range,
            'limit': 50,
            'radius': data['radius']
        }
        headers = {
            'Authorization': 'Bearer %s' % TOKEN,
        }
        url = API_HOST + SEARCH_PATH
        response = requests.request('GET',
                                    url,
                                    headers=headers,
                                    params=url_params)
        if response is None:
            return {"message": "Yelp api call went wrong"}, 500

        try:
            businesses = response.json()['businesses']
        except:
            return response.json(), 500

        unrandomized = []
        for each in businesses:
            business = BusinessModel.find_by_yelp_id(each['id'])
            if business is None:
                address = '\n'.join(
                    each['location']['display_address']).strip('[]')
                business = BusinessModel(each['name'], address, each['id'],
                                         each['rating'], each['price'],
                                         each['display_phone'])
                print("new! " + business.yelp_id)
                photo_ids = get_id(business.yelp_id)
                print("done scraping photo urls!")
                for x in range(0, 3):
                    photomodel = PhotoModel(photo_ids[x], business.yelp_id)
                    photomodel.save_to_db()
                print("done saving photo urls to db!")
                business.photo_ids = str(photo_ids)
                business.save_to_db()
            elif PhotoModel.find_by_photo_yelp_id(
                    "http://kstatic.inven.co.kr/upload/2017/06/22/bbs/i13335449248.jpg",
                    business.yelp_id
            ) and business.yelp_id == PhotoModel.find_by_photo_yelp_id(
                    "http://kstatic.inven.co.kr/upload/2017/06/22/bbs/i13335449248.jpg",
                    business.yelp_id).yelp_id:
                print(business.yelp_id + " currently has 0 photos")
                print("Rescrapting starts now")
                photo_ids = get_id(business.yelp_id)
                for x in range(0, 3):
                    photomodel = PhotoModel(photo_ids[x], business.yelp_id)
                    photomodel.save_to_db()
                    PhotoModel.find_by_photo_yelp_id(
                        "http://kstatic.inven.co.kr/upload/2017/06/22/bbs/i13335449248.jpg",
                        business.yelp_id).delete_from_db()
                business.photo_ids = str(photo_ids)
                business.save_to_db()
                print("done saving actual photo urls to db!")
            for x in range(0, 3):
                unrandomized.append(ast.literal_eval(business.photo_ids)[x])
        randomized = []
        for x in range(0, 30):
            photo_id = unrandomized[random.randint(0, 149)]
            randomized.append(PhotoModel.find_by_photo_id(photo_id).json())
        return randomized
Beispiel #10
0
 def get(self, username):
     business = BusinessModel.find_by_username(username)
     
     if business:
         return business.json()
     return {'message': 'business not found'}, 404