|
@@ -0,0 +1,32 @@
|
|
|
+#
|
|
|
+# Copyright (c) Daniel Sheffield 2023
|
|
|
+#
|
|
|
+# All rights reserved
|
|
|
+#
|
|
|
+# THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
|
|
|
+import yaml
|
|
|
+from yaml.loader import SafeLoader
|
|
|
+from .db_utils import QueryManager
|
|
|
+import re
|
|
|
+
|
|
|
+def parse_recipe(fh, query_manager: QueryManager):
|
|
|
+ contents = yaml.load(fh, Loader=SafeLoader)
|
|
|
+ recipe = {
|
|
|
+ 'ingredients': [],
|
|
|
+ 'feeds': None,
|
|
|
+ 'instructions': None,
|
|
|
+ }
|
|
|
+ for ingredient in contents['ingredients']:
|
|
|
+ units = query_manager.unique_suggestions('unit', unit='')
|
|
|
+ for u in units:
|
|
|
+ match = re.search(
|
|
|
+ r'(?P<product>.*) (?P<quantity>[0-9\.]+)(?P<unit>' f'{u}' r')', ingredient
|
|
|
+ )
|
|
|
+ if not match:
|
|
|
+ continue
|
|
|
+ recipe['ingredients'].append(
|
|
|
+ [match.group('product'), match.group('quantity'), match.group('unit')]
|
|
|
+ )
|
|
|
+ return recipe
|
|
|
+
|
|
|
+
|