Lucii1 commited on
Commit
0a56e27
Β·
1 Parent(s): 8914084

update fn save_json

Browse files
Files changed (1) hide show
  1. app/ultis.py +11 -5
app/ultis.py CHANGED
@@ -25,20 +25,26 @@ def save_string_as_md(raw_string, save_dir, filename="report.md"):
25
  with open(file_path, "w", encoding="utf-8") as f:
26
  f.write(formatted_str)
27
 
28
- print(f"βœ… Report saved to {file_path}")
29
  except Exception as e:
30
- print(f"❌ Failed to save report: {e}")
31
 
 
 
 
 
 
 
32
  def save_json(data, save_dir, filename="output.json"):
33
  try:
34
  file_path = os.path.join(save_dir, filename)
35
 
36
  with open(file_path, "w", encoding="utf-8") as f:
37
- json.dump(data, f, indent=2, ensure_ascii=False)
38
 
39
- print(f"βœ… JSON saved to {file_path}")
40
  except Exception as e:
41
- print(f"❌ Failed to save json: {e}")
42
 
43
  async def convert_keyframes_to_base64(ts_result):
44
  print("[convert_keyframes_to_base64] start")
 
25
  with open(file_path, "w", encoding="utf-8") as f:
26
  f.write(formatted_str)
27
 
28
+ print(f"βœ…[{filename}] Report saved to {file_path}")
29
  except Exception as e:
30
+ print(f"❌ [{filename}] Failed to save report: {e}")
31
 
32
+ def default_encoder(obj):
33
+ try:
34
+ return obj.__dict__
35
+ except Exception:
36
+ return str(obj)
37
+
38
  def save_json(data, save_dir, filename="output.json"):
39
  try:
40
  file_path = os.path.join(save_dir, filename)
41
 
42
  with open(file_path, "w", encoding="utf-8") as f:
43
+ json.dump(data, f, indent=2, ensure_ascii=False, default=default_encoder,)
44
 
45
+ print(f"βœ…[{filename}] JSON saved to {file_path}")
46
  except Exception as e:
47
+ print(f"❌ [{filename}]Failed to save json: {e}")
48
 
49
  async def convert_keyframes_to_base64(ts_result):
50
  print("[convert_keyframes_to_base64] start")