Skip to content

Instantly share code, notes, and snippets.

@neroist
Last active February 17, 2022 13:09
Show Gist options
  • Save neroist/cb71f07fa17430d0751b949dc91ea569 to your computer and use it in GitHub Desktop.
Save neroist/cb71f07fa17430d0751b949dc91ea569 to your computer and use it in GitHub Desktop.
BreakFast API Console Application - Written in Python
"""
A console application for finding breakfast recipes using the BreakFast API.
"""
import requests
response = requests.get('https://breakfastapi.fun/').json()
recipe = response['recipe']
name = recipe['name']
time = recipe['total_duration']
ingredients = recipe['ingredients']
directions = recipe['directions'].split('.')
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 ingredients:
print(f' - {i.title()}')
## --- Print directions ---
print('\nDirections: ')
for i in directions:
print(f'{directions.index(i) + 1}. {i.strip()}')
print() # print newline
@neroist
Copy link
Author

neroist commented Feb 17, 2022

Updated due to update in the BreakFast API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment