def update_business_profile_without_image(self, api_token, hours, name, address, website, number, image_aspect_ratio, features): if self.check_valid_api_token(api_token) == True: try: Zatiq_Businesses.objects(zatiq_token=api_token).update_one(upsert=False, set__business_name=name, set__address=address, set__website=website, set__number=number, set__image_aspect_ratio=image_aspect_ratio, set__hours__monday_start=hours['start']['monday'], set__hours__monday_end=hours['end']['monday'], set__hours__tuesday_start=hours['start']['tuesday'], set__hours__tuesday_end=hours['end']['tuesday'], set__hours__wednesday_start=hours['start']['wednesday'], set__hours__wednesday_end=hours['end']['wednesday'], set__hours__thursday_start=hours['start']['thursday'], set__hours__thursday_end=hours['end']['thursday'], set__hours__friday_start=hours['start']['friday'], set__hours__friday_end=hours['end']['friday'], set__hours__saturday_start=hours['start']['saturday'], set__hours__saturday_end=hours['end']['saturday'], set__hours__sunday_start=hours['start']['sunday'], set__hours__sunday_end=hours['end']['sunday'], set__delivery=features['delivery'], set__takeout=features['takeout'], set__reservation=features['reservation'], set__patio=features['patio'], set__wheelchair_accessible=features['wheelchair_accessible'], set__parking=features['parking'], set__buffet=features['buffet'], set__family_friendly=features['family_friendly'], set__pescetarian_friendly=features['pescetarian_friendly'], set__wifi=features['wifi']) except Exception as e: return("Error \n %s" % (e)) zatiq_business = Zatiq_Businesses.objects(zatiq_token=api_token) if len(zatiq_business) > 0: new_name = zatiq_business[0].business_name new_image = "http://167.99.177.29:5000/image/"+str(zatiq_business[0].image) new_image_aspect_ratio = zatiq_business[0].image_aspect_ratio api_token = zatiq_business[0].zatiq_token else: return('An error occurred') return([new_name, new_image, new_image_aspect_ratio, api_token]) else: return('Could not authenticate')
def business_register(self, business_email, business_password, hours, business_name, address, website, number, image, image_aspect_ratio, features): if not business_email: return(["Please specify your email"]) if not business_password: return(["Please type in your password"]) if not business_name: return(["Please enter your business name"]) if not hours: return(["Please select your business hours"]) check_business_register = Zatiq_Businesses.objects(business_email=business_email) if len(check_business_register) > 0: return(["Business is already registered with this email"]) else: encrypted_password = self.encrypt_password(business_password) api_token = self.generate_zatiq_api_token() image_url = post("http://167.99.177.29:5000/upload/", json={'imagedata': image}) if 'Error' in image_url: return("Invalid image provided") register_business = Zatiq_Businesses.objects(business_email=business_email).update_one(upsert=True, set__business_password=encrypted_password, set__zatiq_token=api_token, set__business_name=business_name, set__address=address, set__website=website, set__number=number, set__image=image_url.text, set__image_aspect_ratio=image_aspect_ratio, set__hours__monday_start=hours['start']['monday'], set__hours__monday_end=hours['end']['monday'], set__hours__tuesday_start=hours['start']['tuesday'], set__hours__tuesday_end=hours['end']['tuesday'], set__hours__wednesday_start=hours['start']['wednesday'], set__hours__wednesday_end=hours['end']['wednesday'], set__hours__thursday_start=hours['start']['thursday'], set__hours__thursday_end=hours['end']['thursday'], set__hours__friday_start=hours['start']['friday'], set__hours__friday_end=hours['end']['friday'], set__hours__saturday_start=hours['start']['saturday'], set__hours__saturday_end=hours['end']['saturday'], set__hours__sunday_start=hours['start']['sunday'], set__hours__sunday_end=hours['end']['sunday'], set__delivery=features['delivery'], set__takeout=features['takeout'], set__reservation=features['reservation'], set__patio=features['patio'], set__wheelchair_accessible=features['wheelchair_accessible'], set__parking=features['parking'], set__buffet=features['buffet'], set__family_friendly=features['family_friendly'], set__pescetarian_friendly=features['pescetarian_friendly'], set__wifi=features['wifi'], set__preferences__halal=False, set__preferences__spicy=True, set__preferences__kosher=False, set__preferences__healthy=False, set__preferences__vegan=False, set__preferences__vegetarian=False, set__preferences__gluten_free=False, set__preferences__lactose_intolerant=False, set__preferences__milk_allergy=False, set__preferences__eggs_allergy=False, set__preferences__fish_allergy=False, set__preferences__crustacean_allergy=False, set__preferences__wheat_allergy=False, set__preferences__soybeans_allergy=False, set__preferences__jain=False, set__preferences__omnivore=False, set__preferences__pescatarian=False, set__preferences__peanuts_allergy=False, set__preferences__treenuts_allergy=False) return(self.business_login(business_email, business_password))
def update_business_profile_with_image(self, api_token, hours, name, address, website, number, image, image_aspect_ratio, features): if self.check_valid_api_token(api_token) == True: old_image_url = Zatiq_Businesses.objects(zatiq_token=api_token)[0].image image_url = post("http://167.99.177.29:5000/update/", json={'imagedata': image, 'imagepath': str(old_image_url)}) if 'Error' in image_url: return("Invalid image provided") try: Zatiq_Businesses.objects(zatiq_token=api_token).update_one(upsert=False, set__business_name=name, set__address=address, set__website=website, set__number=number, set__image=image_url.text, set__image_aspect_ratio=image_aspect_ratio, set__hours__monday_start=hours['start']['monday'], set__hours__monday_end=hours['end']['monday'], set__hours__tuesday_start=hours['start']['tuesday'], set__hours__tuesday_end=hours['end']['tuesday'], set__hours__wednesday_start=hours['start']['wednesday'], set__hours__wednesday_end=hours['end']['wednesday'], set__hours__thursday_start=hours['start']['thursday'], set__hours__thursday_end=hours['end']['thursday'], set__hours__friday_start=hours['start']['friday'], set__hours__friday_end=hours['end']['friday'], set__hours__saturday_start=hours['start']['saturday'], set__hours__saturday_end=hours['end']['saturday'], set__hours__sunday_start=hours['start']['sunday'], set__hours__sunday_end=hours['end']['sunday'], set__delivery=features['delivery'], set__takeout=features['takeout'], set__reservation=features['reservation'], set__patio=features['patio'], set__wheelchair_accessible=features['wheelchair_accessible'], set__parking=features['parking'], set__buffet=features['buffet'], set__family_friendly=features['family_friendly'], set__pescetarian_friendly=features['pescetarian_friendly'], set__wifi=features['wifi']) except Exception as e: return("Error \n %s" % (e)) new_name = name new_image = "http://167.99.177.29:5000/image/"+str(image_url.text) new_image_aspect_ratio = image_aspect_ratio api_token = api_token return([new_name, new_image, new_image_aspect_ratio, api_token]) else: return('Could not authenticate')
def get_linked_food_item_info(self, food_item_id): try: food_item_info = Zatiq_Food_Items.objects(id=food_item_id) except Exception as e: return ("Error \n %s" % (e)) if len(food_item_info) > 0: image = food_item_info[0].image image_aspect_ratio = food_item_info[0].image_aspect_ratio item_name = food_item_info[0].item_name item_price = food_item_info[0].item_price try: restaurant_info = Zatiq_Businesses.objects( id=food_item_info[0].restaurant_id.id) except Exception as e: return ("Error \n %s" % (e)) restaurant_image = restaurant_info[0].image restaurant_image_aspect_ratio = restaurant_info[ 0].image_aspect_ratio restaurant_name = restaurant_info[0].business_name return [ image, image_aspect_ratio, item_name, item_price, restaurant_image, restaurant_image_aspect_ratio, restaurant_name ] else: return []
def get_restaurant_id_by_api_token(self, api_token): valid_token = Zatiq_Businesses.objects(zatiq_token=api_token) if (len(valid_token) > 0): restaurant_id = valid_token[0].id return(restaurant_id) else: return(None)
def update_user_preferences(self, api_token, preferences): if not api_token: return('Could not authenticate') if self.check_valid_api_token(api_token) == True: if self.check_business_or_user(api_token) == 'user': try: Zatiq_Users.objects(zatiq_token=api_token).update_one(upsert=False, set__preferences__halal=preferences['halal'], set__preferences__spicy=preferences['spicy'], set__preferences__kosher=preferences['kosher'], set__preferences__healthy=preferences['healthy'], set__preferences__vegan=preferences['vegan'], set__preferences__vegetarian=preferences['vegetarian'], set__preferences__gluten_free=preferences['gluten_free'], set__preferences__lactose_free=preferences['lactose_intolerant'], set__preferences__milk_allergy=preferences['milk_allergy'], set__preferences__has_eggs=preferences['eggs_allergy'], set__preferences__fish_allergy=preferences['fish_allergy'], set__preferences__crustacean_allergy=preferences['crustacean_allergy'], set__preferences__has_wheat=preferences['wheat_allergy'], set__preferences__has_soybeans=preferences['soybeans_allergy'], set__preferences__jain=preferences['jain'], set__preferences__omnivore=preferences['omnivore'], set__preferences__pescatarian=preferences['pescatarian'], set__preferences__has_peanuts=preferences['peanuts_allergy'], set__preferences__has_treenuts=preferences['treenuts_allergy']) except Exception as e: return("Error \n %s" % (e)) try: get_user_info = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) user_email = get_user_info[0].user_email auth_token = get_user_info[0].auth_token user_name = get_user_info[0].user_name preferences = self.generate_preferences_dict(get_user_info[0].preferences) return([user_email, auth_token, user_name, preferences]) elif self.check_business_or_user(api_token) == 'business': try: Zatiq_Businesses.objects(zatiq_token=api_token).update_one(upsert=False, set__preferences__halal=preferences['halal'], set__preferences__spicy=preferences['spicy'], set__preferences__kosher=preferences['kosher'], set__preferences__healthy=preferences['healthy'], set__preferences__vegan=preferences['vegan'], set__preferences__vegetarian=preferences['vegetarian'], set__preferences__gluten_free=preferences['gluten_free'], set__preferences__lactose_free=preferences['lactose_intolerant'], set__preferences__milk_allergy=preferences['milk_allergy'], set__preferences__has_eggs=preferences['eggs_allergy'], set__preferences__fish_allergy=preferences['fish_allergy'], set__preferences__crustacean_allergy=preferences['crustacean_allergy'], set__preferences__has_wheat=preferences['wheat_allergy'], set__preferences__has_soybeans=preferences['soybeans_allergy'], set__preferences__jain=preferences['jain'], set__preferences__omnivore=preferences['omnivore'], set__preferences__pescatarian=preferences['pescatarian'], set__preferences__has_peanuts=preferences['peanuts_allergy'], set__preferences__has_treenuts=preferences['treenuts_allergy']) except Exception as e: return("Error \n %s" % (e)) try: get_user_info = Zatiq_Businesses.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) user_email = get_user_info[0].business_email user_name = get_user_info[0].business_name preferences = self.generate_preferences_dict(get_user_info[0].preferences) return([user_email, user_name, preferences]) else: return('Could not find that user') else: return('Could not authenticate')
def business_logout(self, api_token): if not api_token: return('Could not authenticate') if self.check_valid_api_token(api_token) == True: logged_business = Zatiq_Businesses.objects(zatiq_token=api_token).update_one(upsert=False, set__zatiq_token='NULL') return('Logged out successfully') else: return('An error occurred')
def get_all_restaurant_names(self, food_items): restaurant_names_list = [] for food_item in range(len(food_items)): try: restaurant_name = Zatiq_Businesses.objects( id=food_items[food_item].restaurant_id.id) except Exception as e: return ("Error \n %s" % (e)) restaurant_names_list.append(restaurant_name[0].business_name) return restaurant_names_list
def business_login(self, business_email, business_password): if not business_email: return(['Please specify your email!']) if not business_password: return(['Please type your password!']) check_business_login = Zatiq_Businesses.objects(business_email=business_email) if len(check_business_login) > 0: encrypted_password = check_business_login[0].business_password if self.verify_password(business_password, encrypted_password) == True: new_api_token = self.generate_zatiq_api_token() try: Zatiq_Businesses.objects(business_email=business_email).update_one(upsert=False, set__zatiq_token=new_api_token) except Exception as e: return("Error \n %s" % (e)) business_name = check_business_login[0].business_name image = "http://167.99.177.29:5000/image/"+str(check_business_login[0].image) image_aspect_ratio = check_business_login[0].image_aspect_ratio return([business_name, new_api_token, image, image_aspect_ratio]) else: return(['Incorrect Password!']) else: return(["No such email address!"])
def check_valid_api_token(self, api_token): try: valid_token = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(valid_token) > 0: return(True) else: try: valid_token = Zatiq_Businesses.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(valid_token) > 0: return(True) else: return(False)
def check_business_or_user(self, api_token): try: zatiq_user = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(zatiq_user) > 0: return('user') else: try: zatiq_user = Zatiq_Businesses.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(zatiq_user) > 0: return('business') else: return('none')
def get_business_profile(self, api_token): if not api_token: return('Could not authenticate') if self.check_valid_api_token(api_token) == True: get_business_info = Zatiq_Businesses.objects(zatiq_token=api_token) restaurant_id = get_business_info[0].id email = get_business_info[0].business_email name = get_business_info[0].business_name website = get_business_info[0].website address = get_business_info[0].address number = get_business_info[0].number features = {'delivery': get_business_info[0].delivery, 'takeout': get_business_info[0].takeout, 'reservation': get_business_info[0].reservation, 'patio': get_business_info[0].patio, 'wheelchair_accessible': get_business_info[0].wheelchair_accessible, 'parking': get_business_info[0].parking, 'buffet': get_business_info[0].buffet, 'family_friendly': get_business_info[0].family_friendly, 'pescetarian_friendly': get_business_info[0].pescetarian_friendly, 'wifi': get_business_info[0].wifi} image = {'base64': "http://167.99.177.29:5000/image/"+str(get_business_info[0].image), 'image_aspect_ratio': get_business_info[0].image_aspect_ratio} hours = self.generate_business_hours(get_business_info[0].hours) restaurant_info = {'restaurant_id': str(restaurant_id), 'email': email, 'name': name, 'website': website, 'hours': hours, 'number': number, 'features': features, 'image': image, 'address': address} return(restaurant_info) else: return('Could not authenticate')
def get_restaurant_info(self, restaurant_id): try: zatiq_business = Zatiq_Businesses.objects(id=restaurant_id) except Exception as e: return("Error \n %s" % (e)) if len(zatiq_business) > 0: restaurant_id = zatiq_business[0].id email = zatiq_business[0].business_email name = zatiq_business[0].business_name website = zatiq_business[0].website hours = self.generate_business_hours(zatiq_business[0].hours) number = zatiq_business[0].number features = {'delivery': zatiq_business[0].delivery, 'takeout': zatiq_business[0].takeout, 'reservation': zatiq_business[0].reservation, 'patio': zatiq_business[0].patio, 'wheelchair_accessible': zatiq_business[0].wheelchair_accessible, 'parking': zatiq_business[0].parking, 'buffet': zatiq_business[0].buffet, 'family_friendly': zatiq_business[0].family_friendly, 'pescetarian_friendly': zatiq_business[0].pescetarian_friendly, 'wifi': zatiq_business[0].wifi} image = {'base64': "http://167.99.177.29:5000/image/"+str(zatiq_business[0].image), 'image_aspect_ratio': zatiq_business[0].image_aspect_ratio} address = zatiq_business[0].address restaurant_info = {'restaurant_id': str(restaurant_id), 'email': email, 'name': name, 'website': website, 'hours': hours, 'number': number, 'features': features, 'image': image, 'address': address} return(restaurant_info) else: return('Could not find a restaurant with that id')
def get_nearby_restaurants(self, api_token): if not api_token: return('Could not authenticate') if self.check_valid_api_token(api_token) == True: try: zatiq_food_items = Zatiq_Businesses.objects() except Exception as e: return("Error \n %s" % (e)) if len(zatiq_food_items) > 0: if len(zatiq_food_items) > 10: restaurants = random.sample(zatiq_food_items, 10) restaurants_list = self.generate_restaurants_list(restaurants) return(restaurants_list) else: restaurants_list = self.generate_restaurants_list(zatiq_food_items) return(restaurants_list) else: return([]) else: return('Could not authenticate')
def get_business_name_by_id(self, business_id): try: business_name = Zatiq_Businesses.objects(id=business_id) except Exception as e: return ("Error \n %s" % (e)) return (business_name[0].business_name)
def get_interior_photos_by_restaurant(self, api_token): if self.check_valid_api_token(api_token) == True: restaurant = Zatiq_Businesses.objects(zatiq_token=api_token)[0].id interior_photos = Zatiq_Interiors.objects(restaurant_id=restaurant) result = self.generate_photos_dict(interior_photos) return(result)
def check_valid_api_token(self, api_token): valid_token = Zatiq_Businesses.objects(zatiq_token=api_token) if len(valid_token) > 0: return(True) else: return(False)
def check_api_token_exists(self, api_token): check_api_token = Zatiq_Businesses.objects(zatiq_token=api_token) if len(check_api_token) > 0: self.generate_zatiq_api_token() else: return(False)