-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
70 lines (48 loc) · 1.7 KB
/
Copy pathmodels.py
File metadata and controls
70 lines (48 loc) · 1.7 KB
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
import json
from typing import NamedTuple, List, Optional
class Ingredient:
def __init__(self, iid, name, image, unit=None):
self.iid = iid
self.name = name
self.image = image
self.unit = unit
with open('./data/ingredient.json') as f:
ingredients = {data['iid']: Ingredient(**data) for data in json.load(f)}
class RecipeIngredient:
def __init__(self, iid, count=None, weight=None, comment=None):
self.iid = iid
self.count = count
self.weight = weight
self.comment = comment
@property
def ingredient(self):
return ingredients[self.iid]
class Action:
def __init__(self, image, timer=None, description=None):
self.image = image
self.timer = timer
self.description = description
class Procedure:
def __init__(self, step, actions=None):
self.step = step
self.actions = actions
@classmethod
def load(cls, d):
d['actions'] = [Action(**data) for data in d['actions']]
return cls(**d)
class Recipe:
def __init__(self, id, name, level, image_url, ingredient_image, ingredients, procedures):
self.id = id
self.name = name
self.level = level
self.image_url = image_url
self.ingredient_image = ingredient_image
self.ingredients = ingredients
self.procedures = procedures
@classmethod
def load(cls, d):
d['ingredients'] = [RecipeIngredient(**data) for data in d['ingredients']]
d['procedures'] = [Procedure.load(data) for data in d['procedures']]
return cls(**d)
with open('./data/recipes.json') as f:
recipes = {data['id']: Recipe.load(data) for data in json.load(f)}