예제 #1
0
def get_birthday_meal_results_by_params(allergies, is_kids_party,
                                        max_prep_time):
    conn = my_connect.connect_to_db()
    res = []
    max_prep_time_in_sec = str(max_prep_time * 3600)
    meals_by_id = get_recipe_from_db_by_birthday_meal_filter(
        allergies, is_kids_party, max_prep_time_in_sec, conn)
    for meal_res in meals_by_id:
        meals = {}
        recipe_id = meal_res["snack_recipe_id"]
        meals["snack"] = mysql_recipe_queries.get_recipe_and_ingredients_by_id(
            recipe_id, conn)
        recipe_id = meal_res["main_recipe_id"]
        meals["main"] = mysql_recipe_queries.get_recipe_and_ingredients_by_id(
            recipe_id, conn)
        recipe_id = meal_res["side_recipe_id"]
        meals["side"] = mysql_recipe_queries.get_recipe_and_ingredients_by_id(
            recipe_id, conn)
        recipe_id = meal_res["cake_recipe_id"]
        meals[
            "dessert"] = mysql_recipe_queries.get_recipe_and_ingredients_by_id(
                recipe_id, conn)
        res.append(meals)
    print(res)
    conn.close()
    return res
예제 #2
0
def get_drink_results_by_params(alcoholic, ingredients, glasses,
                                max_ingredients, side_dish):
    conn = my_connect.connect_to_db()
    res = []
    drinks_by_id = get_drinks_from_db(alcoholic, ingredients, glasses,
                                      max_ingredients, conn)

    for drink_res in drinks_by_id:
        drink = {}
        drink_id = drink_res['drink_id']
        drink['drink'] = drink_res
        drink['ingredients'] = get_drink_ingredients_from_db(drink_id, conn)
        res.append(drink)
    res_snacks = get_snacks_results(side_dish, conn)
    conn.close()
    return res, res_snacks
def get_professional_meals_results():
    conn = my_connect.connect_to_db()
    res = []
    meals_by_id = get_recipes_from_db_by_professional_meal_filter(conn)
    for meal_res in meals_by_id:
        meal = {}
        recipe_id = meal_res['recipe_id']
        meal['meal'] = meal_res
        meal['meal']['prep_time'] = mysql_recipe_queries.get_time_str(
            meal['meal']['prep_time'])
        meal[
            'ingredients'] = mysql_recipe_queries.get_recipe_ingredients_from_db(
                recipe_id, conn)
        res.append(meal)
    conn.close()
    return res
def get_romantic_meal_results_by_params(main_ingredient, side_ingredient, dessert_taste, max_prep_time):
    conn = my_connect.connect_to_db()
    res = []
    max_prep_time_in_sec = str(max_prep_time * 3600)
    meals_by_id = get_recipe_from_db_by_romantic_meal_filter(main_ingredient, side_ingredient, dessert_taste,
                                                             max_prep_time_in_sec, conn)
    for meal_res in meals_by_id:
        meals = {}
        recipe_id = meal_res["main_recipe_id"]
        meals["main"] = mysql_recipe_queries.get_recipe_and_ingredients_by_id(recipe_id, conn)
        recipe_id = meal_res["side_recipe_id"]
        meals["side"] = mysql_recipe_queries.get_recipe_and_ingredients_by_id(recipe_id, conn)
        recipe_id = meal_res["dessert_recipe_id"]
        meals["dessert"] = mysql_recipe_queries.get_recipe_and_ingredients_by_id(recipe_id, conn)
        res.append(meals)
    conn.close()
    return res
예제 #5
0
def get_veg_recipes_results_by_params(min_veg_num):
    conn = my_connect.connect_to_db()
    res = []
    recipes = get_veg_recipes_from_db(min_veg_num, conn)
    for recipe in recipes:
        meal = {}
        recipe_id = recipe['recipe_id']
        meal['meal'] = recipe
        meal['meal']['prep_time'] = mysql_recipe_queries.get_time_str(
            meal['meal']['prep_time'])
        meal[
            'ingredients'] = mysql_recipe_queries.get_recipe_ingredients_from_db(
                recipe_id, conn)
        print(meal['ingredients'])
        res.append(meal)
    print(res)
    conn.close()
    return res
def get_holiday_meal_results_by_params(holiday, max_prep_time,
                                       min_num_of_guests, num_of_dishes):
    conn = my_connect.connect_to_db()
    res = []
    max_prep_time_in_sec = str(max_prep_time * 3600)
    print(max_prep_time_in_sec)
    meals_by_id = get_recipe_from_db_by_holiday_meal_filter(
        holiday, max_prep_time_in_sec, min_num_of_guests, num_of_dishes, conn)
    for meal_res in meals_by_id:
        meals = {}
        for num in range(1, num_of_dishes + 1):
            recipe_id = meal_res["recipe_id_" + str(num)]
            meals["recipe_" + str(
                num)] = mysql_recipe_queries.get_recipe_and_ingredients_by_id(
                    recipe_id, conn)
        res.append(meals)
    print(res)
    conn.close()
    return res
예제 #7
0
def get_ethnic_meal_results_by_params(max_prep_time, courses, cuisine):
    conn = my_connect.connect_to_db()
    print("ok")
    res = []
    unlimited = False
    if int(max_prep_time) == 4:
        unlimited = True

    max_prep_time_in_sec = int(max_prep_time) * 3600
    meals_by_id = get_recipe_from_db_by_ethnic_meal_filter(
        unlimited, max_prep_time_in_sec, courses, cuisine, conn)
    print(meals_by_id)
    for meal_res in meals_by_id:
        meals = {}
        for course in courses:
            recipe_id = meal_res[course.lower() + "_recipe_id"]
            meals[course.lower()] = get_recipe_and_ingredients_by_id(
                recipe_id, conn)
        res.append(meals)
    conn.close()
    return res
예제 #8
0
def get_easy_meals_results_by_params(max_prep_time, max_ingredients,
                                     ingredients_common_level):
    conn = my_connect.connect_to_db()
    print("connected")
    res = []
    max_prep_time_in_sec = str(int(max_prep_time) * 60)
    meals_by_id = get_recipes_from_db_by_easy_meal_filter(
        max_prep_time_in_sec, max_ingredients, ingredients_common_level, conn)
    for meal_res in meals_by_id:
        meal = {}
        snack_id = meal_res['recipe_id']
        meal['meal'] = meal_res
        meal['meal']['prep_time'] = mysql_recipe_queries.get_time_str(
            meal['meal']['prep_time'])
        meal[
            'ingredients'] = mysql_recipe_queries.get_recipe_ingredients_from_db(
                snack_id, conn)
        res.append(meal)
    print(res)
    conn.close()
    return res