Files
scraper/scraper/utils.py
T
2026-06-12 23:10:33 -07:00

17 lines
465 B
Python

import json
import os
from .models import ScrapeResult
def save_results_to_json(result: ScrapeResult, file_path: str):
"""
Saves the scrape result to a JSON file.
"""
# Ensure the directory exists
os.makedirs(os.path.dirname(file_path), exist_ok=True)
# Convert Pydantic model to dict
data = result.model_dump(mode='json')
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=4, ensure_ascii=False)