-
Notifications
You must be signed in to change notification settings - Fork 1
/
recipes2json.py
executable file
·105 lines (99 loc) · 2.38 KB
/
recipes2json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
import json
import sys
import yaml
from pathlib import Path
from slugify import slugify
def load_recipes(recipes_dir):
r = []
for recipe in recipes_dir.glob('*.yml'):
with recipe.open("r") as f:
data = yaml.safe_load(f)
data["key"] = slugify(f"{recipe.parent.name}-{recipe.stem}")
if not data.get("images"):
data["images"] = []
r.append(data)
return sorted(r, key=lambda x: x["title"])
if __name__ == "__main__":
recipes = []
recipes.append(
{
"category": "Baking & Desserts",
"subcategory": "Bars",
"img": "bars.jpg",
"recipes": load_recipes(Path("recipes/baking-and-desserts/bars/"))
}
)
recipes.append(
{
"category": "Baking & Desserts",
"subcategory": "Cakes & Muffins",
"img": "cakes.jpg",
"recipes": load_recipes(Path("recipes/baking-and-desserts/cakes/"))
}
)
recipes.append(
{
"category": "Baking & Desserts",
"subcategory": "Cookies",
"img": "cookies.jpg",
"recipes": load_recipes(Path("recipes/baking-and-desserts/cookies/"))
}
)
recipes.append(
{
"category": "Baking & Desserts",
"subcategory": "Misc",
"img": "desserts.jpg",
"recipes": load_recipes(Path("recipes/baking-and-desserts/desserts/"))
}
)
recipes.append(
{
"category": "Breads",
"subcategory": "",
"img": "breads.jpg",
"recipes": load_recipes(Path("recipes/breads/"))
}
)
recipes.append(
{
"category": "Canning",
"subcategory": "",
"img": "canning.jpg",
"recipes": load_recipes(Path("recipes/canning/"))
}
)
recipes.append(
{
"category": "Miscellaneous",
"subcategory": "",
"img": "misc.jpg",
"recipes": load_recipes(Path("recipes/miscellaneous/"))
}
)
recipes.append(
{
"category": "Main Courses",
"subcategory": "",
"img": "mains.jpg",
"recipes": load_recipes(Path("recipes/main-dishes/"))
}
)
recipes.append(
{
"category": "Salads",
"subcategory": "",
"img": "salads.jpg",
"recipes": load_recipes(Path("recipes/salads/"))
}
)
recipes.append(
{
"category": "Soups & Stews",
"subcategory": "",
"img": "soups-and-stews.jpg",
"recipes": load_recipes(Path("recipes/soups-and-stews/"))
}
)
print(json.dumps(recipes))