Oriaz commited on
Commit
fd4b655
·
verified ·
1 Parent(s): 87489b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -14,16 +14,31 @@ from ingestion_chroma import retrieve_info_from_db
14
  ################################### TOOLS ##################################################
15
  ############################################################################################
16
 
17
- def find_key(data, target_key):
18
- if isinstance(data, dict):
19
- for key, value in data.items():
20
- if key == target_key:
21
- return value
22
- else:
23
- result = find_key(value, target_key)
24
- if result is not None:
25
- return result
26
- return "Indicator not found"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  ############################################################################################
29
 
@@ -65,7 +80,7 @@ class ESRS_info_tool(Tool):
65
  with open('./data/dico_esrs.json') as json_data:
66
  dico_esrs = json.load(json_data)
67
 
68
- result = find_key(dico_esrs, indicator)
69
 
70
  return result
71
 
 
14
  ################################### TOOLS ##################################################
15
  ############################################################################################
16
 
17
+ def search_key(d, target_key):
18
+ """
19
+ Recherche une clé dans un dictionnaire imbriqué.
20
+
21
+ :param d: Le dictionnaire dans lequel chercher.
22
+ :param target_key: La clé à chercher.
23
+ :return: Une liste des valeurs associées à la clé trouvée.
24
+ """
25
+ results = []
26
+
27
+ def recursive_search(d):
28
+ if isinstance(d, dict):
29
+ for key, value in d.items():
30
+ if key == target_key:
31
+ results.append(value)
32
+ if isinstance(value, dict):
33
+ recursive_search(value)
34
+ elif isinstance(value, list):
35
+ for item in value:
36
+ if isinstance(item, dict):
37
+ recursive_search(item)
38
+
39
+ recursive_search(d)
40
+
41
+ return results
42
 
43
  ############################################################################################
44
 
 
80
  with open('./data/dico_esrs.json') as json_data:
81
  dico_esrs = json.load(json_data)
82
 
83
+ result = search_key(dico_esrs, indicator)
84
 
85
  return result
86