From 0f9f7b237c775c95719cdd6475b4d0c2780ac3a9 Mon Sep 17 00:00:00 2001 From: Thelie Date: Wed, 18 May 2022 10:54:44 +0200 Subject: [PATCH] Add leeway for people using too many >s in their metadata declarations. --- cook2tex.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cook2tex.py b/cook2tex.py index cb54973..225f7b7 100644 --- a/cook2tex.py +++ b/cook2tex.py @@ -68,15 +68,26 @@ def parse_recipe_from_file(path): serving_keys = ["servings", "serves"] -time_keys = ["time", "total time"] +time_keys = ["time", "total time", "total-time"] def get_metadata_value(keys, recipe, substitute="N/A"): + + # Sometimes people use too many >s for their metadata… + meta_data = { rem_beginning_duplicate(key, ">").strip(): recipe["metadata"][key] for key in recipe["metadata"].keys() } + for key in keys: - if key in recipe["metadata"].keys(): - return recipe["metadata"][key] + if key in meta_data.keys(): + return meta_data[key] return substitute + +def rem_beginning_duplicate(in_str, rem_char): + while in_str and in_str[0] == rem_char: + in_str = in_str[1:] + + return in_str + def get_step_ingredients(step): ingredients = []