Skip to content

Commit c31e1e9

Browse files
committed
wiki fetcher logging path
1 parent a70b1ad commit c31e1e9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

graphfaker/fetchers/wiki.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
print(page['sections'], page['links'][:5], page['references'][:5])
2222
wiki.export_page_json(page, "graph_theory.json")
2323
"""
24-
24+
import os
2525
import json
2626
from typing import Dict, Any, List, Optional
2727
import wikipedia
@@ -73,6 +73,10 @@ def export_page_json(page: Dict[str, Any], filename: str) -> None:
7373
page_data: Dict returned by `fetch_page`.
7474
filename: Destination JSON file path.
7575
"""
76-
with open(filename, 'w', encoding='utf-8') as f:
76+
77+
abs_path = os.path.abspath(filename)
78+
os.makedirs(os.path.dirname(abs_path) or ".", exist_ok=True)
79+
80+
with open(abs_path, 'w', encoding='utf-8') as f:
7781
json.dump(page, f, ensure_ascii=False, indent=2)
78-
print(f"Exported Wikipedia page data to '{filename}'")
82+
print(f"Exported Wikipedia page data to '{abs_path}'")

0 commit comments

Comments
 (0)