@@ -38,7 +38,7 @@ def convert_json_to_html(json_path, output_path):
3838 return output_path
3939
4040def main ():
41- # Convert all JSON files in the json/ directory
41+ # Convert all JSON files in the json/ directory (including subdirectories)
4242 json_dir = "json"
4343 charts_dir = "charts"
4444
@@ -48,24 +48,37 @@ def main():
4848
4949 os .makedirs (charts_dir , exist_ok = True )
5050
51- json_files = [f for f in os .listdir (json_dir ) if f .endswith ('.json' )]
51+ # Walk through all directories and files
52+ converted_count = 0
53+ failed_count = 0
5254
53- if not json_files :
54- print (f"No JSON files found in '{ json_dir } ' directory" )
55- return
55+ for root , dirs , files in os .walk (json_dir ):
56+ for filename in files :
57+ if filename .endswith ('.json' ):
58+ json_path = os .path .join (root , filename )
59+
60+ # Calculate relative path from json_dir
61+ rel_path = os .path .relpath (json_path , json_dir )
5662
57- print (f"Found { len (json_files )} JSON file(s) to convert" )
63+ # Create corresponding output path in charts_dir
64+ html_rel_path = rel_path .replace ('.json' , '.html' )
65+ html_path = os .path .join (charts_dir , html_rel_path )
5866
59- for json_file in json_files :
60- json_path = os .path .join (json_dir , json_file )
61- html_filename = json_file .replace ('.json' , '.html' )
62- html_path = os .path .join (charts_dir , html_filename )
67+ # Create subdirectories if needed
68+ os .makedirs (os .path .dirname (html_path ), exist_ok = True )
6369
64- try :
65- convert_json_to_html (json_path , html_path )
66- print (f"✅ Converted { json_file } → { html_filename } " )
67- except Exception as e :
68- print (f"❌ Failed to convert { json_file } : { e } " )
70+ try :
71+ convert_json_to_html (json_path , html_path )
72+ print (f"✅ Converted { rel_path } → { html_rel_path } " )
73+ converted_count += 1
74+ except Exception as e :
75+ print (f"❌ Failed to convert { rel_path } : { e } " )
76+ failed_count += 1
77+
78+ if converted_count == 0 and failed_count == 0 :
79+ print (f"No JSON files found in '{ json_dir } ' directory" )
80+ else :
81+ print (f"\n ✨ Converted { converted_count } file(s), { failed_count } failed" )
6982
7083if __name__ == "__main__" :
7184 main ()
0 commit comments