コード例 #1
0
def getMeal(uid, price, nick):
    user = api.getUser(uid)
    nearby = api.search(uid, nick)
    price = int(10000 * float(price) /
                (100 + float(user["tip"]))) / 100.0 / 1.0875
    # return json.dumps(nearby)
    choices_outer = []
    for rest in nearby:
        if rest["mino"] <= price and rest["is_delivering"] == 1:
            rest_data = api.getDetails(rest["id"])
            choices = []
            addons = []
            if api.cuisineCheck(rest_data["cuisine"], uid):
                for category in rest_data["menu"]:
                    for listing in category["children"]:
                        if float(listing["price"]) <= price:
                            listing["rest"] = rest["id"]
                            foodItem = meal(listing)
                            if foodItem.price < 4.85 or foodItem.price < 0.6 * price or not api.valid(
                                    listing):
                                base = addons
                            else:
                                base = choices
                            if "children" in listing:
                                for option in listing["children"]:
                                    if api.valid(option):
                                        title = option["name"]
                                        flex = api.checkFlexibility(title)
                                        if "children" in option:
                                            for op in option["children"]:
                                                optionItem = meal(op)
                                                foodItem.addOption(
                                                    title, optionItem, flex)
                            base.append(foodItem)
            choices_outer.append([choices, addons])
    meals = []
    spent = 0
    score = 0
    while score < random.random():
        rest_index = random.randrange(len(choices_outer))
        rest_pick = choices_outer[rest_index]
        if len(rest_pick[0]) != 0:
            meal_index = random.randrange(len(rest_pick[0]))
            meal_pick = rest_pick[0][meal_index]
            final_meal, total_price = meal_pick.pickOptions(price)
            if total_price <= price - spent:
                meals.append(final_meal.toDict())
                spent = spent + total_price
            elif spent < total_price:
                meals = final_meal.toDict()
                spent = total_price
            score = (float(spent) / price)**2 + score
        else:
            score = score - 0.01
            # print "swap"
    return json.dumps({"core": meals, "total": spent})
コード例 #2
0
ファイル: views.py プロジェクト: LamaUrbain/LamaWeb
def ajaxUser(request):
    username = request.matchdict.get("username", None)
    if not username:
        request.response.status = 400
        return {'error': 'Invalid User'}
    context = globalContext(request)
    context['user'] = api.getUser(request, username=username)
    context['itineraries'] = api.getItineraries(request,
                                                username=username,
                                                favorite='true')
    return context
コード例 #3
0
ファイル: main.py プロジェクト: hellovai/mealmaniac
def getMeal(uid, price, nick):
    user = api.getUser(uid)
    nearby = api.search(uid, nick)
    price = int(10000 * float(price) / (100 + float(user["tip"]))) / 100.0 / 1.0875
    # return json.dumps(nearby)
    choices_outer = []
    for rest in nearby:
        if rest["mino"] <= price and rest["is_delivering"] == 1:
            rest_data = api.getDetails(rest["id"])
            choices = []
            addons = []
            if api.cuisineCheck(rest_data["cuisine"], uid):
                for category in rest_data["menu"]:
                    for listing in category["children"]:
                        if float(listing["price"]) <= price:
                            listing["rest"] = rest["id"]
                            foodItem = meal(listing)
                            if foodItem.price < 4.85 or foodItem.price < 0.6 * price or not api.valid(listing):
                                base = addons
                            else:
                                base = choices
                            if "children" in listing:
                                for option in listing["children"]:
                                    if api.valid(option):
                                        title = option["name"]
                                        flex = api.checkFlexibility(title)
                                        if "children" in option:
                                            for op in option["children"]:
                                                optionItem = meal(op)
                                                foodItem.addOption(title, optionItem, flex)
                            base.append(foodItem)
            choices_outer.append([choices, addons])
    meals = []
    spent = 0
    score = 0
    while score < random.random():
        rest_index = random.randrange(len(choices_outer))
        rest_pick = choices_outer[rest_index]
        if len(rest_pick[0]) != 0:
            meal_index = random.randrange(len(rest_pick[0]))
            meal_pick = rest_pick[0][meal_index]
            final_meal, total_price = meal_pick.pickOptions(price)
            if total_price <= price - spent:
                meals.append(final_meal.toDict())
                spent = spent + total_price
            elif spent < total_price:
                meals = final_meal.toDict()
                spent = total_price
            score = (float(spent) / price) ** 2 + score
        else:
            score = score - 0.01
            # print "swap"
    return json.dumps({"core": meals, "total": spent})
コード例 #4
0
ファイル: views.py プロジェクト: LamaUrbain/LamaWeb
def ajaxFormLogin(request):
    if 'username' in request.POST and 'password' in request.POST:
        # call api to login
        auth = api.authenticate(request,
                                username=request.POST['username'],
                                password=request.POST['password'])
        # add auth token to session
        request.session['auth_token'] = auth['token']
        # get api user
        user = api.getUser(request, username=request.POST["username"])
        # add user to session
        request.session['auth_user'] = user
    # redirect to /
    return HTTPFound(location='/#profile')
コード例 #5
0
def login(email, pwd):
    uid = api.getUid(email, pwd)
    user = api.getUser(uid)
    return json.dumps(user)
コード例 #6
0
ファイル: main.py プロジェクト: hellovai/mealmaniac
def login(email, pwd):
    uid = api.getUid(email, pwd)
    user = api.getUser(uid)
    return json.dumps(user)
コード例 #7
0
ファイル: app.py プロジェクト: bigpe/Ecole42_HyperTube
def getUser():
    return jsonify(api.getUser())