from grocy.request import Request from grocy.conf import Configuration from grocy.entity import Entity import logging class Recipe(object): GET_RECIPES_FULFILLMENT_URL_TEMPLATE = '{domain}/api/recipes/fulfillment' GET_RECIPE_FULFILLMENT_URL_TEMPLATE = '{domain}/api/recipes/{recipeId}/fulfillment' GET_RECIPES_POS_FULFILLMENT_URL_TEMPLATE = '{domain}/api/recipes/pos/fulfillment' GET_RECIPE_POS_FULFILLMENT_URL_TEMPLATE = '{domain}/api/recipes/{recipeId}/pos/{recipeId}/fulfillment' def __init__(self, id=None): self.conf = Configuration() self.conf.load() self.id = id def get_ingredient_requirements(self, recipe_id=None): logger = logging.getLogger('recipe.get_ingredient_requirements') def get_fulfillments(self): logger = logging.getLogger('recipe.get_requirements') if self.id: url = self.GET_RECIPE_FULFILLMENT_URL_TEMPLATE.format(domain=self.conf.domain, recipeId=self.id) else: url = self.GET_RECIPES_FULFILLMENT_URL_TEMPLATE.format(domain=self.conf.domain) request = Request('get', url) try: return request.send() except Exception as e: logger.error(e) raise e def get(self): # Get list of available ingredients if self.id: entity = Entity(name='recipes') recipe = entity.get(id=self.id) if type(recipe) is list: pass