This commit is contained in:
hay-kot 2021-03-05 12:49:48 -09:00
commit 73b310a333
2 changed files with 15 additions and 5 deletions

View file

@ -1,5 +1,6 @@
import html
import re
from datetime import datetime
from typing import List
from slugify import slugify
@ -24,10 +25,13 @@ class Cleaner:
Returns:
dict: cleaned recipe dictionary
"""
recipe_data["totalTime"] = Cleaner.time(recipe_data.get("totalTime"))
recipe_data["description"] = Cleaner.html(recipe_data.get("description", ""))
recipe_data["prepTime"] = Cleaner.time(recipe_data.get("prepTime"))
recipe_data["performTime"] = Cleaner.time(recipe_data.get("performTime"))
# Times
recipe_data["prepTime"] = Cleaner.time(recipe_data.get("prepTime", None))
recipe_data["performTime"] = Cleaner.time(recipe_data.get("performTime", None))
recipe_data["totalTime"] = Cleaner.time(recipe_data.get("totalTime", None))
recipe_data["recipeYield"] = Cleaner.yield_amount(
recipe_data.get("recipeYield")
)
@ -144,8 +148,13 @@ class Cleaner:
return yld
@staticmethod
def time(time_entry) -> str:
if type(time_entry) == type(None):
def time(time_entry):
print(time_entry, type(time_entry))
if time_entry == None:
return None
elif type(time_entry) == datetime:
print(time_entry)
elif type(time_entry) != str:
return str(time_entry)
elif time_entry != None:
return time_entry

View file

@ -25,6 +25,7 @@ def create_from_url(url: str) -> Recipe:
"""
r = requests.get(url)
new_recipe = extract_recipe_from_html(r.text, url)
print(new_recipe)
new_recipe = Cleaner.clean(new_recipe, url)
new_recipe = download_image_for_recipe(new_recipe)