-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
87 lines (81 loc) · 3.09 KB
/
main.py
File metadata and controls
87 lines (81 loc) · 3.09 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from Mongo_class import Mongo_pizza
from Eaternity_class import Eaternity_class
from migros_class import MigrosAPI
from tqdm import tqdm
class Logic():
def __init__(self):
print("Loading...")
self.pm = Mongo_pizza()
self.ec = Eaternity_class()
self.ma = MigrosAPI()
self.user = "Prasanna"
self.kitchen = "Kitchen_Prassana"
print("Server ready")
def conver_ingredient(self, mongo_dict, migros_dict):
"""
Join data fron ingredients
"""
return {
"id": mongo_dict['id'],
"names": [{"language": "en", "value": mongo_dict['name']}],
"amount": mongo_dict['amount'],
"unit": mongo_dict['unit'],
"origin": "Germany",
"transport": "ground",
"production": mongo_dict['production'],
"conservation":mongo_dict['conservation']
}
def return_data_CO2(self, pizza_name, location="Switzerland"):
"""
Return CO2 data
pizza_name: string data
"""
a = self.ec.create_kitchen(self.user, self.kitchen, location)
if a[1]:
self.pm.get_error(a[0])
ingredients = self.pm.get_pizza(pizza_name)['Ingredients']
aux_ingr = [self.pm.get_ingredient(i) for i in ingredients]
aux = [self.conver_ingredient(i,[]) for i in aux_ingr]
aux, a = self.ec.put_recipe("Recipe", self.kitchen,
"Recipe", aux, location)
if a:
self.pm.get_error(aux)
raise Exception
self.pm.insert_log(pizza_name,
ingredients,
aux['recipe']['co2-value'],
self.user, self.kitchen, "Return co2")
return aux
def return_data_pizza(self, pizza_name, location="Switzerland"):
"""
Return ingredients from pizza
pizza_name: string data
"""
self.ec.create_kitchen(self.user, self.kitchen, location)
ingredients = self.pm.get_pizza(pizza_name)['Ingredients']
self.pm.insert_log(pizza_name,
ingredients,
-1,
self.user, self.kitchen, "Return ingredients")
return {"ingredients": ingredients}
def return_nutrients_ingredients(self, ingredient):
"""
Return data
ingredients: list data
"""
aux_ingr = self.pm.get_ingredient(ingredient)
aux = {}
try:
aux[" Nutritional"] = self.ma.get_nutrients(
aux_ingr['name-ger'])
except IndexError as e:
aux[" Nutritional"] = "None"
self.pm.get_error("Error Migros API: " + str(e))
except KeyError as e:
aux[" Nutritional"] = "None"
self.pm.get_error("Error Migros API: " + str(e))
self.pm.insert_log("",
[ingredient],
-1,
self.user, self.kitchen, "Return nutrients")
return aux