Last active
February 17, 2022 13:09
-
-
Save neroist/cb71f07fa17430d0751b949dc91ea569 to your computer and use it in GitHub Desktop.
BreakFast API Console Application - Written in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated due to update in the BreakFast API.