Skip to content

Instantly share code, notes, and snippets.

@neroist
Last active February 17, 2022 13:09
Show Gist options
  • Select an option

  • Save neroist/cb71f07fa17430d0751b949dc91ea569 to your computer and use it in GitHub Desktop.

Select an option

Save neroist/cb71f07fa17430d0751b949dc91ea569 to your computer and use it in GitHub Desktop.

Revisions

  1. neroist revised this gist Feb 17, 2022. 1 changed file with 16 additions and 9 deletions.
    25 changes: 16 additions & 9 deletions breakfast.py
    Original file line number Diff line number Diff line change
    @@ -4,26 +4,33 @@

    import requests


    response = requests.get('https://breakfastapi.fun/').json()
    recipe = response['recipe']

    name = response['Recipe Name']
    time = response['Cook Time (Minutes)']
    ingredients = response['Ingredients']
    directions = response['Directions'].split('.')
    name = recipe['name']
    time = recipe['total_duration']
    ingredients = recipe['ingredients']
    directions = recipe['directions'].split('.')

    del directions[directions.index('')]
    del directions[directions.index('')] # directions has an empyt string in it
    directions.append("And enjoy!") # add message to the end of the directions

    print('Recipe Name:', name, '\n')
    print('Cook Time:', time, f'({time / 60} hours)', '\n')
    # ! be careful of repeating decimals

    ## --- Print ingredients ---
    print('Ingredients:')

    for i in eval(ingredients.replace("'", '"')):
    print(f' - {i}')
    for i in ingredients:
    print(f' - {i.title()}')

    ## --- Print directions ---
    print('\nDirections: ')

    for i in directions:
    print(f'{directions.index(i) + 1}. {i.strip()}')

    print() # print newline


    print() # print newline
  2. neroist revised this gist Feb 10, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions breakfast.py
    Original file line number Diff line number Diff line change
    @@ -25,3 +25,5 @@

    for i in directions:
    print(f'{directions.index(i) + 1}. {i.strip()}')

    print() # print newline
  3. neroist created this gist Feb 9, 2022.
    27 changes: 27 additions & 0 deletions breakfast.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    """
    A console application for finding breakfast recipes using the BreakFast API.
    """

    import requests

    response = requests.get('https://breakfastapi.fun/').json()

    name = response['Recipe Name']
    time = response['Cook Time (Minutes)']
    ingredients = response['Ingredients']
    directions = response['Directions'].split('.')

    del directions[directions.index('')]

    print('Recipe Name:', name, '\n')
    print('Cook Time:', time, f'({time / 60} hours)', '\n')

    print('Ingredients:')

    for i in eval(ingredients.replace("'", '"')):
    print(f' - {i}')

    print('\nDirections: ')

    for i in directions:
    print(f'{directions.index(i) + 1}. {i.strip()}')