def addUser(): global Rest body = request.json key = "user:"******":details" sender = str(body['ID']) body.pop('ID') user = redDict(redis=pot_con, key=key) arch = redDict(redis=pot_arc, key=key) if 'decoded_address' not in arch: arch = user arch['confirmed_carts'] = 0 for key in body: user[key] = body[key] if ('subscribed' in user): body['subscribed'] = user['subscribed'] if ('decoded_address' not in user): if ('lat' and 'long' in user): get_cluster_hotel(sender, user['lat'], user['long']) s = str(get_geocode(int(user['lat']), int(user['long']))) user[ 'decoded_address'] = '26/C, Hosur Road, Electronics City Phase 1, Electronic City, Bengaluru, Karnataka 560100' body['decoded_address'] = user['decoded_address'] body['location'] = 1 else: body['location'] = 0 print(json.dumps(body)) yield json.dumps(body)
def claimOffer(sender): global OffersDB #print(OffersDB) result = {'status': [], 'remaining': [], 'dish': []} body = request.json body = str(body) body = json.loads(body) key = "user:"******":details" user = redDict(redis=pot_con, key=key) if ('confirmed_carts' in user): cart = redDict(redis=pot_con, key="user:"******":cart:" + str(user['confirmed_carts'] + 1)) else: cart = redDict(redis=pot_con, key="user:"******":cart:1") user['confirmed_carts'] = 0 for item in body: print(item) print(OffersDB[OffersDB['dish'] == item]) if (OffersDB[OffersDB['dish'] == item]['qty_left'].tolist()[0] >= int( body[item])): cart[item] = body[item] result['dish'].append(item) result['status'].append('Yes') result['remaining'].append( OffersDB[OffersDB['dish'] == item]['qty_left'].tolist()[0]) else: result['dish'].append(item) result['status'].append('No') result['remaining'].append( OffersDB[OffersDB['dish'] == item]['qty_left'].tolist()[0]) yield json.dumps(result)
def showCart1(sender): global OffersDB user = redDict(redis = pot_con, key = "user:"******":details") if('confirmed_carts' in user): cart = redDict(redis = pot_con, key = "user:"******":cart:"+str(user['confirmed_carts']+1)) else: cart = redDict(redis = pot_con, key = "user:"******":cart:1") user['confirmed_carts'] = 0 result = {'cart':'','status':[],'qty':[],'dish':[],'remaining':[],'price':[]} if(len(cart)!=0): result['cart'] = 'Yes' for item in cart: if((OffersDB[OffersDB['dish']==item]['qty_left'].tolist()[0])>=(int(cart[item]))): result['dish'].append(item) result['qty'].append(int(cart[item])) result['status'].append('Yes') result['price'].append(OffersDB[OffersDB['dish']==item]['offerPrice'].tolist()[0]) result['remaining'].append(OffersDB[OffersDB['dish']==item]['qty_left'].tolist()[0]) else: result['dish'].append(item) result['qty'].append(int(cart[item])) result['status'].append('No') result['price'].append(OffersDB[OffersDB['dish']==item]['offerPrice'].tolist()[0]) result['remaining'].append(OffersDB[OffersDB['dish']==item]['qty_left'].tolist()[0]) print(result) return (result) else: result['cart'] = 'No' print(result) return (result)
def addRestaurant(): body = request.json rest_id = next(rest_ids) key = "rest:"+str(rest_id)+":details" rest = redDict(redis = pot_con, key = key) for key in body: rest[key] = body[key]
def updateUser(): body = request.json key = "user"+str(body["id"])+":details" user = redDict(redis = pot_con, key = key) for key in body: if key != 'id': user[key] = body[key]
def confirmCart(sender, number): global OffersDB cart = showCart1(sender) result = {'name': '', 'number': '', 'address': '', 'total': 0, 'body': {}} print(cart) resultcart = {} if (cart['cart'] == 'No'): return json.dumps(result) else: total = 0 for i in range(len(cart['dish'])): if (cart['status'][i] == 'No'): cart['cart'] = 'No' return json.dumps(result) total += int(cart['price'][i]) * int(cart['qty'][i]) user = redDict(redis=pot_con, key="user:"******":details") user['number'] = number user['location'] = 0 if ('confirmed_carts' in user): user['confirmed_carts'] = int(user['confirmed_carts']) + 1 else: user['confirmed_carts'] = 1 result['name'] = user['name'] result['number'] = user['number'] result['total'] = total result['body'] = cart result['address'] = user['decoded_address'] return json.dumps(result)
def addOffer(): global OffersDB, offerRests, Rest Offers = [] body = request.json rests = [] ide = [] print(2) for i in range(len(body['data'])): body['data'][i]['ID'] = random.randint(100, 999) key = "rest:" + str(body['data'][i]['restID']) + ":details" rest = redDict(redis=pot_arc, key=key) body['data'][i]['restName'] = rest['name'] body['data'][i][ 'link'] = 'http://genii.ai/activebots/Babadadhaba/img/db/' + body[ 'data'][i]['dish'].replace(" ", "-") + ".jpg" Offers.append(body['data'][i]) print(3) if (rest['name'] not in rests): rests.append(rest['name']) if (body['data'][i]['restID'] not in offerRests): offerRests.append(body['data'][i]['restID']) if (body['data'][i]['restID'] not in ide): ide.append(body['data'][i]['restID']) print(4) DB = pd.read_json(json.dumps(Offers), orient='records') print(5) OffersDB = OffersDB.append(DB, ignore_index=True) print(6) yield "Successfully added dishes." send_data(ide, rests, DB) print(10)
def updateRestaurant(): body = request.json key = "rest:" + str(body["ID"]) + ":details" rest = redDict(redis=pot_arc, key=key) for key in body: rest[key] = body[key] print(json.dumps(body)) yield json.dumps(body)
def deleteUser(UserId): body = request.json UserId = body['ID'] key = "user:"******":details" user = redDict(redis=pot_con, key=key) for keys in body: user.pop(keys) print(json.dumps(body)) yield json.dumps(body)
def addRestaurant(): body = request.json rest_id = next(rest_ids) key = "rest:"+str(rest_id)+":details" rest = redDict(redis = pot_arc, key = key) rest['ID'] = rest_id body['ID'] = rest_id for key in body: rest[key] = body[key] print(json.dumps(body)) yield json.dumps(body)
def getnearestRest(sender): global offerRests user = redDict(redis = pot_con, key = "user:"******":details") if('lat' and 'long' in user): lat = user['lat'] lon = user['long'] else: return [] nearest = {} for rest in offerRests: restaurant = redDict(redis = pot_arc, key = "rest:" + str(rest) + ":details") if('lat' and 'long' in restaurant): distance = Haversine((lat,lon), (restaurant['lat'],restaurant['long'])).km if(distance <= int(restaurant['radius'])): nearest[restaurant['name']] = distance result = [] for key in sorted(nearest, key=lambda x: nearest[x]): result.append(key) print(result) print("surya") return result
def addRestaurant(): global Rest body = request.json rest_id = next(rest_ids) key = "rest:" + str(rest_id) + ":details" rest = redDict(redis=pot_arc, key=key) rest['ID'] = rest_id body['ID'] = rest_id for key in body: rest[key] = body[key] Rest.append({ 'name': rest['name'], 'ID': rest_id, 'lat': rest['lat'], 'long': rest['long'], 'radius': rest['radius'] }) print(json.dumps(body)) yield json.dumps(body)
def getUser(UserId): key = "user:"******":details" user = redDict(redis=pot_con, key=key) data = {} if (len(user) != 0): data['name'] = user['name'] if ('subscribed' not in user): data['subscribed'] = 0 data['location'] = 0 else: data['subscribed'] = user['subscribed'] if ('decoded_address' and 'lat' and 'long' in user): data['decoded_address'] = user['decoded_address'] data['location'] = 1 else: data['location'] = 0 else: data['name'] = '' data['subscribed'] = 0 data['location'] = 0 print(json.dumps(data)) yield json.dumps(data)
def addUser(): body = request.json key = "user:"******":details" user = redDict(redis = pot_con, key = key) for key in body: user[key] = body[key]
def updateRestaurant(): body = request.json key = "rest:"+str(body["id"])+":details" rest = redDict(redis = pot_con, key = key) for key in body: rest[key] = body[key]
def saved_address(sender): key = "user:"******":details" user = redDict(redis=pot_con, key=key) user['location'] = 1