from io import BytesIO import requests import validators from cookbook.helper.ingredient_parser import IngredientParser from cookbook.helper.recipe_url_import import parse_servings, parse_servings_text, parse_time from cookbook.integration.integration import Integration from cookbook.models import Ingredient, Recipe, Step class Cookmate(Integration): def import_file_name_filter(self, zip_info_object): return zip_info_object.filename.endswith('.xml') def get_files_from_recipes(self, recipes, el, cookie): raise NotImplementedError('Method not implemented in storage integration') def get_recipe_from_file(self, file): recipe_xml = file recipe = Recipe.objects.create( name=recipe_xml.find('title').text.strip(), created_by=self.request.user, internal=True, space=self.request.space) if recipe_xml.find('preptime') is not None and recipe_xml.find('preptime').text is not None: recipe.working_time = parse_time(recipe_xml.find('preptime').text.strip()) if recipe_xml.find('cooktime') is not None and recipe_xml.find('cooktime').text is not None: recipe.waiting_time = parse_time(recipe_xml.find('cooktime').text.strip()) if recipe_xml.find('quantity') is not None and recipe_xml.find('quantity').text is not None: recipe.servings = parse_servings(recipe_xml.find('quantity').text.strip()) recipe.servings_text = parse_servings_text(recipe_xml.find('quantity').text.strip()) if recipe_xml.find('url') is not None and recipe_xml.find('url').text is not None: recipe.source_url = recipe_xml.find('url').text.strip() if recipe_xml.find('description') is not None: # description is a list of