def validteCaptchaSelection(images): valid = True apiReq = DataModels.ClarifaiRequest() apiReqImages = [] for img in images: apiReq.inputs.append({"data": {"image": {"url": img['url']}}}) resp = DataModels.AppResponse() data = apiReq.serialize() headers = {'Authorization': CLARIFAI_AUTH_HEADER, 'content-type':'application/json'} r = requests.post(url = CLARIFAI_MODEL_URL, json = data, headers = headers) jsonResp = r.json() if jsonResp['status']['code'] == 10000: for img in images: isPie = False for output in jsonResp['outputs']: if output['input']['data']['image']['url'] == img['url']: for c in output['data']['concepts']: if c['name'] == 'pie' and c['value'] > 0.5: isPie = True break break if not isPie == img['selected']: valid = False break if valid: resp = DataModels.AppResponse(True, 'OK','OK') else: resp = DataModels.AppResponse(False,'FAIL','Invalid Submission') return resp
def getMenuList(typeId, input): menuLists = DataModels.List_Menu_Details() try: menu_json = { "name": [], } session = sessionRepo() db_result_cities = session.query(DbClasses.menus_Repository).with_entities(DbClasses.menus_Repository.city).distinct(DbClasses.menus_Repository.city)\ .filter(DbClasses.menus_Repository.city.ilike("%" + input + "%")).all() for value in db_result_cities: menuLists.menuList.append(value.city) session = sessionRepo() db_result_menus = session.query( DbClasses.menus_Repository).with_entities( DbClasses.menus_Repository.menu_name).filter( DbClasses.menus_Repository.type_id == typeId).filter( DbClasses.menus_Repository.menu_name.ilike("%" + input + "%")).all() for value in db_result_menus: menuLists.menuList.append(value.menu_name) #menuLists.menuList = menu_json menuLists.isFailure = False menuLists.message = "Menu list fetched from MenuRepository" except Exception as error: store_error_log(error) menuLists.isFailure = True menuLists.message = "Menu list not fetched from MenuRepository" return menuLists
def getCaptchaImages(count, previousImages): images = [] urls = [] x = 1 while x <= count: r = requests.get(url = RANDOM_IMAGE_URL) data = r.json() url = data['imageUrl'] if url not in urls and url not in previousImages: img = DataModels.CaptchaImage(len(images) + 1,data['imageUrl']) urls.append(url) images.append(img) x = x + 1 return images
def get_single_menu_details(menuId): Menus = DataModels.List_Menu_Details() try: session = sessionRepo() db_result = session.query( DbClasses.menus_Repository, DbClasses.menuRoom_Repository, DbClasses.room_Repository).from_statement( text('''select room.id,app_room.room_id,menu.menu_id, menu.menu_name,menu.place_address,menu.city,menu.state,menu.country,menu.map, app_room.room_name,room.cost,room.amenities,room.room_info from tbl_app_menu_m as menu INNER JOIN tbl_menu_room_t as room ON menu.menu_id = room.menu_id INNER JOIN tbl_app_room_m as app_room ON app_room.room_id = room.room_id where menu.menu_id = :id ''' )).params(id=menuId).all() if db_result is None: response = BaseEntitySet( True, "Selected Menu list is not fetched from MenuRepository") return response for value in db_result: menu_json = { "id": value.menus_Repository.menu_id, "name": value.menus_Repository.menu_name, "address": value.menus_Repository.place_address, "city": value.menus_Repository.city, "state": value.menus_Repository.state, "country": value.menus_Repository.country, "type": value.room_Repository.room_name, "cost": value.menuRoom_Repository.cost, "amenities": value.menuRoom_Repository.amenities, "info": value.menuRoom_Repository.room_info, "map": value.menus_Repository.map, "galId": "gal-" + str(value.menus_Repository.menu_id) } Menus.menuList.append(menu_json) Menus.isFailure = False Menus.message = "Menu list fetched from MenuRepository" except SQLAlchemyError as error: store_error_log(error) Menus.isFailure = True Menus.message = "Menu list fetched from MenuRepository" return Menus.menuList
def getImages(): prev_images = [] if 'captcha-prev-images' in session: prev_images = session['captcha-prev-images'].split('|') images = APIManager.getCaptchaImages(6, prev_images) cur_images = '' for i in images: if cur_images == '': cur_images = i.url else: cur_images += '|' + i.url session['captcha-prev-images'] = cur_images print cur_images resp = DataModels.AppResponse(True, 'OK', 'OK') resp.data = [i.serialize() for i in images] return jsonify(resp.serialize())
def get_menus(typeId): menuList = DataModels.List_Menu_Details() try: session = sessionRepo() db_result = session.query( DbClasses.menus_Repository, DbClasses.menuRoom_Repository, DbClasses.room_Repository).from_statement( text('''select room.id,app_room.room_id,menu.menu_id, menu.menu_name,menu.place_address,menu.city,menu.state,menu.country, app_room.room_name,room.cost,room.amenities,room.room_info from tbl_app_menu_m as menu INNER JOIN tbl_menu_room_t as room ON menu.menu_id = room.menu_id INNER JOIN tbl_app_room_m as app_room ON app_room.room_id = room.room_id where menu.type_id = :id''' )).params(id=typeId).all() if db_result is None: menuList.isFailure = True menuList.message = "Menu list not fetched from MenuRepository" return menuList for value in db_result: menu_json = { "id": value.menus_Repository.menu_id, "name": value.menus_Repository.menu_name, "address": value.menus_Repository.place_address, "city": value.menus_Repository.city, "state": value.menus_Repository.state, "country": value.menus_Repository.country, "type": value.room_Repository.room_name, "cost": value.menuRoom_Repository.cost, "amenities": value.menuRoom_Repository.amenities, "info": value.menuRoom_Repository.room_info } menuList.menuList.append(menu_json) menuList.isFailure = False except SQLAlchemyError as error: store_error_log(error) menuList.isFailure = True menuList.message = "Menu list not fetched from MenuRepository" return menuList
def filter_menu_list(typeId, city, fromValue, toValue): Menus = DataModels.List_Menu_Details() menuIdList = list() menu_json = dict() try: session = sessionRepo() db_result = session.query(DbClasses.menus_Repository)\ .filter(DbClasses.menus_Repository.type_id == typeId).filter(DbClasses.menus_Repository.city.ilike("%" + city + "%")).all() if db_result is None or db_result == '': Menus.isFailure = False Menus.message = "Selected Menu ID not fetched from MenuRepository" return Menus for data in db_result: menuIdList.append(data.menu_id) db_info_result = session.query(DbClasses.menuRoom_Repository)\ .filter(DbClasses.menuRoom_Repository.menu_id.in_(menuIdList)).filter(DbClasses.menuRoom_Repository.cost <=toValue).filter(DbClasses.menuRoom_Repository.cost >= fromValue).all() if db_info_result is None or db_result == '': Menus.isFailure = False Menus.message = "Selected Menu info not fetched from MenuRoomRepository" return Menus for value, item in zip(db_result, db_info_result): menu_json = { "id": value.menu_id, "name": value.menu_name, "address": value.place_address, "city": value.city, "state": value.state, "country": value.country, "cost": item.cost, "amenities": item.amenities, "info": item.room_info, "galId": "gal-" + str(value.menu_id) } Menus.menuList.append(menu_json) return Menus except SQLAlchemyError as error: store_error_log(error) Menus.isFailure = True Menus.message = "Selected Menu list is not fetched from MenuRepository" return Menus
def get_searched_menu(input, typeId): search_result = DataModels.List_Menu_Details() #search_result = [] if input == '': search_result.isFailure = False search_result.message = "Search Input Field is blank" return search_result try: session = sessionRepo() db_result = session.query(DbClasses.menus_Repository).with_entities( DbClasses.menus_Repository.menu_id).filter( or_( DbClasses.menus_Repository.city.ilike("%" + input + "%"), DbClasses.menus_Repository.menu_name. ilike("%" + input + "%"))).filter( DbClasses.menus_Repository.type_id.ilike("%" + typeId + "%")).all() if db_result is None or db_result == '': search_result.isFailure = False search_result.message = "Selected Menu ID not fetched from MenuRepository" return search_result for id in range(len(db_result)): val = db_result[id] result = get_single_menu_details(val[0]) search_result.menuList.append(result) if len(search_result.menuList) == 0: search_result.isFailure = False search_result.message = "Selected Menu ID not fetched from MenuRepository" return search_result #for data in search_result.menuList: #print(search_result.menuList[0][0]['city']) except SQLAlchemyError as error: store_error_log(error) search_result.isFailure = True search_result.message = "Selected Menu ID not fetched from MenuRepository" return search_result