Esempio n. 1
0
def importBSMXRecipe(data):
    logger.debug("Start parsing BSMX recipe")

    #BSMX format use not valid entities
    def correct_bsmx_entities(text):
        text = re.sub('(ld|rd|rs)quo;', 'quot;', text)
        text = text.replace('°', '°')
        return text

    try:
        tree = ElementTree.fromstring(
            correct_bsmx_entities(open(data, 'r').read()))
    except TypeError:
        tree = data
    except FileNotFoundError:
        tree = ElementTree.fromstring(correct_bsmx_entities(data))
    except:
        raise

    recipe = Recipe()

    recipe_root = tree.find('.//Recipe')

    recipe.name = recipe_root.find('F_R_NAME').text
    recipe.brewer = recipe_root.find('F_R_BREWER').text
    equipment = recipe_root.find('F_R_EQUIPMENT')
    recipe.volume = bsmx_volume_conversion(
        float(equipment.find('F_E_BATCH_VOL').text))
    recipe.efficiency = float(equipment.find('F_E_EFFICIENCY').text)
    recipe.boil = float(equipment.find('F_E_BOIL_TIME').text)
    bsmx_type = {
        '0': model.constants.RECIPE_TYPE_EXTRACT,
        '1': model.constants.RECIPE_TYPE_PARTIAL_MASH,
        '2': model.constants.RECIPE_TYPE_ALL_GRAIN
    }
    recipe.type = bsmx_type[recipe_root.find('F_R_TYPE').text]
    style = recipe_root.find('F_R_STYLE')
    recipe.style = '%s%s. %s' % (style.find('F_S_NUMBER').text,
                                 chr(64 + int(style.find('F_S_LETTER').text) %
                                     26), style.find('F_S_NAME').text)
    recipe.recipeNotes = recipe_root.find('F_R_NOTES').text
    recipe.mash = importBSMXMash(recipe_root.find('F_R_MASH'))

    elements = recipe_root.find('Ingredients').find('Data')
    for element in elements.findall('Grain'):
        recipe.listeFermentables.append(importBSMXFermentable(element))
    for element in elements.findall('Hops'):
        recipe.listeHops.append(importBSMXHop(element))
    for element in elements.findall('Yeast'):
        recipe.listeYeasts.append(importBSMXYeast(element))
    for element in elements.findall('Misc'):
        recipe.listeMiscs.append(importBSMXMisc(element))

    logger.debug("End parsing BSMX recipe")
    return recipe
Esempio n. 2
0
def importBSMXRecipe(data):
    logger.debug("Start parsing BSMX recipe")

    # BSMX format use not valid entities
    def correct_bsmx_entities(text):
        text = re.sub("(ld|rd|rs)quo;", "quot;", text)
        text = text.replace("°", "°")
        return text

    try:
        tree = ElementTree.fromstring(correct_bsmx_entities(open(data, "r").read()))
    except TypeError:
        tree = data
    except FileNotFoundError:
        tree = ElementTree.fromstring(correct_bsmx_entities(data))
    except:
        raise

    recipe = Recipe()

    recipe_root = tree.find(".//Recipe")

    recipe.name = recipe_root.find("F_R_NAME").text
    recipe.brewer = recipe_root.find("F_R_BREWER").text
    equipment = recipe_root.find("F_R_EQUIPMENT")
    recipe.volume = bsmx_volume_conversion(float(equipment.find("F_E_BATCH_VOL").text))
    recipe.efficiency = float(equipment.find("F_E_EFFICIENCY").text)
    recipe.boil = float(equipment.find("F_E_BOIL_TIME").text)
    bsmx_type = {
        "0": model.constants.RECIPE_TYPE_EXTRACT,
        "1": model.constants.RECIPE_TYPE_PARTIAL_MASH,
        "2": model.constants.RECIPE_TYPE_ALL_GRAIN,
    }
    recipe.type = bsmx_type[recipe_root.find("F_R_TYPE").text]
    style = recipe_root.find("F_R_STYLE")
    recipe.style = "%s%s. %s" % (
        style.find("F_S_NUMBER").text,
        chr(64 + int(style.find("F_S_LETTER").text) % 26),
        style.find("F_S_NAME").text,
    )
    recipe.recipeNotes = recipe_root.find("F_R_NOTES").text
    recipe.mash = importBSMXMash(recipe_root.find("F_R_MASH"))

    elements = recipe_root.find("Ingredients").find("Data")
    for element in elements.findall("Grain"):
        recipe.listeFermentables.append(importBSMXFermentable(element))
    for element in elements.findall("Hops"):
        recipe.listeHops.append(importBSMXHop(element))
    for element in elements.findall("Yeast"):
        recipe.listeYeasts.append(importBSMXYeast(element))
    for element in elements.findall("Misc"):
        recipe.listeMiscs.append(importBSMXMisc(element))

    logger.debug("End parsing BSMX recipe")
    return recipe
Esempio n. 3
0
def importBSMXRecipe(data):
    logger.debug("Start parsing BSMX recipe")
    
    #BSMX format use not valid entities
    def correct_bsmx_entities(text):
        text = re.sub('(ld|rd|rs)quo;', 'quot;', text)
        text = text.replace('°', '°')
        return text
    try:
        tree = ElementTree.fromstring(correct_bsmx_entities(open(data, 'r').read()))
    except TypeError:
        tree = data
    except FileNotFoundError:
        tree = ElementTree.fromstring(correct_bsmx_entities(data))
    except:
        raise

    recipe = Recipe()

    recipe_root = tree.find('.//Recipe')

    recipe.name = recipe_root.find('F_R_NAME').text
    recipe.brewer = recipe_root.find('F_R_BREWER').text
    equipment = recipe_root.find('F_R_EQUIPMENT')
    recipe.volume = bsmx_volume_conversion(float(equipment.find('F_E_BATCH_VOL').text))
    recipe.efficiency = float(equipment.find('F_E_EFFICIENCY').text)
    recipe.boil = float(equipment.find('F_E_BOIL_TIME').text)
    bsmx_type = {
        '0': model.constants.RECIPE_TYPE_EXTRACT,
        '1': model.constants.RECIPE_TYPE_PARTIAL_MASH,
        '2': model.constants.RECIPE_TYPE_ALL_GRAIN
    }
    recipe.type = bsmx_type[recipe_root.find('F_R_TYPE').text]
    style = recipe_root.find('F_R_STYLE')
    recipe.style = '%s%s. %s' % (style.find('F_S_NUMBER').text, chr(64+int(style.find('F_S_LETTER').text) % 26),
                                 style.find('F_S_NAME').text)
    recipe.recipeNotes = recipe_root.find('F_R_NOTES').text
    recipe.mash = importBSMXMash(recipe_root.find('F_R_MASH'))

    elements = recipe_root.find('Ingredients').find('Data')
    for element in elements.findall('Grain'):
        recipe.listeFermentables.append(importBSMXFermentable(element))
    for element in elements.findall('Hops'):
        recipe.listeHops.append(importBSMXHop(element))
    for element in elements.findall('Yeast'):
        recipe.listeYeasts.append(importBSMXYeast(element))
    for element in elements.findall('Misc'):
        recipe.listeMiscs.append(importBSMXMisc(element))

    logger.debug("End parsing BSMX recipe")
    return recipe
Esempio n. 4
0
def importBeerXMLRecipe(data):
    logger.debug("Start parsing recipe")
    try:
        tree = ElementTree.parse(data)
    except TypeError:
        tree = data
    except IOError:
        tree = ElementTree.fromstring(data)
    except:
        raise

    recipe = Recipe()
    recipe.path = data

    presentation = tree.find('.//RECIPE')
    fermentables = tree.findall('.//FERMENTABLE')
    hops = tree.findall('.//HOP')
    levures = tree.findall('.//YEAST')
    misc = tree.findall('.//MISC')
    style = tree.find('.//STYLE')
    mash = tree.find('.//MASH')

    for element in presentation:
        if 'NAME' == element.tag:
            recipe.name = element.text
            logger.debug(" Recipe name: %s", recipe.name)
        if 'BREWER' == element.tag:
            recipe.brewer = element.text
            logger.debug(" Recipe brewer: %s", recipe.brewer)
        if 'TYPE' == element.tag:
            if "All Grain" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_ALL_GRAIN
            elif "Partial Mash" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_PARTIAL_MASH
            elif "Extract" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_EXTRACT
            logger.debug(" Recipe type: %s", recipe.type)
        if "BATCH_SIZE" == element.tag:
            recipe.volume = float(element.text)
            logger.debug(" Recipe volume: %s", recipe.volume)
        if "EFFICIENCY" == element.tag:
            recipe.efficiency = float(element.text)
            logger.debug(" Recipe efficiency: %s", recipe.efficiency)
        if "BOIL_TIME" == element.tag:
            recipe.boil = float(element.text)
            logger.debug(" Recipe boil time: %s", recipe.boil)
        if "NOTES" == element.tag:
            recipe.recipeNotes = element.text
            logger.debug(" Recipe notes: %s", recipe.recipeNotes)
    try:
        for element in style:
            if "NAME" == element.tag:
                recipe.style = element.text
    except TypeError:
        recipe.style = ""

    try:
        recipe.mash = importBeerXMLMash(mash)
    except:
        pass

    for element in fermentables:
        recipe.listeFermentables.append(importBeerXMLFermentable(element))
    for element in hops:
        recipe.listeHops.append(importBeerXMLHop(element))
    for element in levures:
        recipe.listeYeasts.append(importBeerXMLYeast(element))
    for element in misc:
        recipe.listeMiscs.append(importBeerXMLMisc(element))

    logger.debug("End parsing recipe")
    return recipe
Esempio n. 5
0
def importBeerXMLRecipe(data):
    logger.debug("Start parsing recipe")
    try:
        tree = ElementTree.parse(data)
    except TypeError:
        tree = data
    except FileNotFoundError:
        tree = ElementTree.fromstring(data)
    except:
        raise

    recipe = Recipe()
    recipe.path = data

    presentation = tree.find('.//RECIPE')
    fermentables = tree.findall('.//FERMENTABLE')
    hops = tree.findall('.//HOP')
    levures = tree.findall('.//YEAST')
    misc = tree.findall('.//MISC')
    style = tree.find('.//STYLE')
    mash = tree.find('.//MASH')

    for element in presentation:
        if 'NAME' == element.tag:
            recipe.name = element.text
            logger.debug(" Recipe name: %s", recipe.name)
        if 'BREWER' == element.tag:
            recipe.brewer = element.text
            logger.debug(" Recipe brewer: %s", recipe.brewer)
        if 'TYPE' == element.tag:
            if "All Grain" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_ALL_GRAIN
            elif "Partial Mash" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_PARTIAL_MASH
            elif "Extract" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_EXTRACT
            logger.debug(" Recipe type: %s", recipe.type)
        if "BATCH_SIZE" == element.tag:
            recipe.volume = float(element.text)
            logger.debug(" Recipe volume: %s", recipe.volume)
        if "EFFICIENCY" == element.tag:
            recipe.efficiency = float(element.text)
            logger.debug(" Recipe efficiency: %s", recipe.efficiency)
        if "BOIL_TIME" == element.tag:
            recipe.boil = float(element.text)
            logger.debug(" Recipe boil time: %s", recipe.boil)
        if "NOTES" == element.tag:
            recipe.recipeNotes = element.text
            logger.debug(" Recipe notes: %s", recipe.recipeNotes)
    try:
        for element in style:
            if "NAME" == element.tag:
                recipe.style = element.text
    except TypeError:
        recipe.style = ""

    try:
        recipe.mash = importBeerXMLMash(mash)
    except:
        pass

    for element in fermentables:
        recipe.listeFermentables.append(importBeerXMLFermentable(element))
    for element in hops:
        recipe.listeHops.append(importBeerXMLHop(element))
    for element in levures:
        recipe.listeYeasts.append(importBeerXMLYeast(element))
    for element in misc:
        recipe.listeMiscs.append(importBeerXMLMisc(element))

    logger.debug("End parsing recipe")
    return recipe