Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] added suggest food and user recipe suggestion for specific interest #252

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions modules/food.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
import requests
import click
import json
import requests

FOOD_URL = 'https://www.themealdb.com/api/json/v1/1/search.php?s='
RANDOM_FOOD_URL = 'https://www.themealdb.com/api/json/v1/1/random.php'
INGREDIENTS = []


def food_request(food):
req = requests.get(FOOD_URL + food)
parsed_response = req.json()
food_json = parsed_response['meals']
return food_json


def get_meal_instructions(meal):
click.echo(food_request(meal)[0]['strInstructions'])


def get_ingridients(meal):
for ingNumber in range(1, 20):
ingredient = food_request(meal)[0]['strIngredient' + str(ingNumber)]
qty = food_request(meal)[0]['strMeasure' + str(ingNumber)]
if ingredient:
if not qty:
output_str = "{} (as needed)".format(ingredient)
else:
output_str = "{} x {}".format(ingredient, qty)
click.echo(output_str)
INGREDIENTS.append(output_str)


@click.group()
Expand All @@ -11,6 +38,45 @@ def food():
"""


@food.command()
def suggest_food():
"""
Suggests a random meal from the meal DB
"""

def get_meal_suggestion():
req = requests.get(RANDOM_FOOD_URL)
parsed_response = req.json()
food_json = parsed_response['meals']
meal = food_json[0]['strMeal']

click.echo('Try this amazing ' + meal + ', it\'s delicious!')
click.echo("You will need following :")
click.echo('------------')
get_ingridients(meal)
click.echo('------Follow the instructions below------ :')
get_meal_instructions(meal)
click.echo('Bon appetit ! =) ')

get_meal_suggestion()


@food.command()
@click.argument('meal')
def food_select(meal):
"""
Displays recipe with measurements and instructions for selected meal preparation
"""

def chosen_food(meal):
click.echo('-----Here are ingridients for your {0}!-----'.format(meal))
get_ingridients(meal)
click.echo('-----And here are the instructions for {0}-----'.format(meal))
get_meal_instructions(meal)

chosen_food(meal)


@food.command()
def suggest_drinks():
"""
Expand Down