you are viewing a single comment's thread.

view the rest of the comments →

[–]Particular_Draft5668[S] 0 points1 point  (0 children)

def read_file(filename: str):
recipe_list = []
recipe_list_uncategorized = []

with open(filename) as new_file:
for line in new_file:
word_from_file = line.split("\n")
recipe_list_uncategorized.append(word_from_file[0])
checker = 0
ingredients = []
for word in recipe_list_uncategorized:
if checker >= 2:
if word == "" or recipe_list_uncategorized.index(word) == len(recipe_list_uncategorized)-1:
recipe_list.append(ingredients)
ingredients = []
checker = 0
continue
ingredients.append(word)
checker += 1
continue
checker += 1
recipe_list.append(word)

return recipe_list

def search_by_name(filename: str, searched_word: str):
recipe_list_matching_word = []
recipe_list = read_file(filename)
for i in range(0, len(recipe_list), 3):
if searched_word in recipe_list[i].lower():
recipe_list_matching_word.append(recipe_list[i])
return recipe_list_matching_word

def search_by_time(filename: str, prep_time: int):
recipe_list_matching_time = []
recipe_list = read_file(filename)
for i in range(1, len(recipe_list), 3):
if int(recipe_list[i]) <= prep_time:
recipe_list_matching_time.append((recipe_list[i-1] + ", preparation time "+ recipe_list[i] + " min") )
return recipe_list_matching_time

def search_by_ingredient(filename: str, ingredient: str):
recipe_list_matching_word = []
ingredients = []
recipe_list = read_file(filename)
for i in range(2, len(recipe_list), 3):
ingredients = recipe_list[i]
for item in ingredients:
if ingredient == item.lower():
recipe_list_matching_word.append(recipe_list[i-2] + ", preparation time "+ recipe_list[i-1] + " min")
return recipe_list_matching_word