abinazebinoy commited on
Commit
0e43bbf
·
1 Parent(s): fad15e0

fix(M-09): guard os.makedirs() in save_json() against empty dirname -- filenames without path component no longer crash

Browse files
Files changed (1) hide show
  1. scrapers/base_scraper.py +5 -1
scrapers/base_scraper.py CHANGED
@@ -46,7 +46,11 @@ class BaseScraper:
46
 
47
  def save_json(self, data, filepath):
48
  import json
49
- os.makedirs(os.path.dirname(filepath), exist_ok=True)
 
 
 
 
50
  with open(filepath, "w", encoding="utf-8") as f:
51
  json.dump(data, f, indent=2, ensure_ascii=False)
52
  logger.info(f"[{self.name}] Saved: {filepath}")
 
46
 
47
  def save_json(self, data, filepath):
48
  import json
49
+ # M-09 FIX: dirname("output.json") returns "" -- makedirs("") crashes.
50
+ # Guard with: only call makedirs if there is actually a directory component.
51
+ dir_path = os.path.dirname(filepath)
52
+ if dir_path:
53
+ os.makedirs(dir_path, exist_ok=True)
54
  with open(filepath, "w", encoding="utf-8") as f:
55
  json.dump(data, f, indent=2, ensure_ascii=False)
56
  logger.info(f"[{self.name}] Saved: {filepath}")