-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSON_Manager.py
71 lines (55 loc) · 2.71 KB
/
JSON_Manager.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
import json
class JSON_Manager():
def __init__(self):
pass
def SQL_to_JSON(self, sql_data):
sql_data = sql_data.replace("\\r\\n", " ")
sql_data = sql_data.replace("('", "")
sql_data = sql_data.replace("',)", "")
sql_data = sql_data.replace("'", '"')
sql_data = sql_data.replace('\t','')
sql_data = sql_data.replace('\n','')
sql_data = sql_data.replace(',}','}')
sql_data = sql_data.replace(',]',']')
return sql_data
def JSON_to_Rezept_String(self, json_rezept):
rezept_string = ""
for (key, value) in json_rezept.items():
if key == "beschreibung":
rezept_string = rezept_string + "\n" + value + "\n\n"
if key == "ingredients":
for (key, value) in value.items():
if key == "spirituosen":
for (key, value) in value.items():
temp = self.switch_zutaten("alkohol", key)
if temp != "invalid":
rezept_string = rezept_string + temp + ": " + str(value) + " cl \n"
if key == "filler":
for (key, value) in value.items():
temp = self.switch_zutaten("softdrinks", key)
if temp != "invalid":
rezept_string = rezept_string + temp + ": " + str(value) + " cl \n"
temp = self.switch_zutaten("feste_zutaten", key)
if temp != "invalid":
rezept_string = rezept_string + temp + ": " + str(value) + " \n"
if key == "garnitur":
rezept_string = rezept_string + "Garnitur: "
for i in value:
temp = self.switch_zutaten("garnitur",i)
rezept_string = rezept_string + str(temp) + ", "
rezept_string = rezept_string[:-2]
if key == "zubereitung":
rezept_string = rezept_string + "\n\n" + value
return rezept_string
######### Swtches für Cocktailrezepte
def switch_zutaten(self, type, argument):
json_dict = ""
with open('Zutaten_Dictionary.json') as JSON:
json_dict = json.load(JSON)
if type in json_dict:
if argument in json_dict[type]:
return json_dict[type][argument]
else:
return "invalid"
else:
return "invalid"