mirror of
https://github.com/j93es/oauth-backend.git
synced 2026-06-04 06:51:51 +09:00
27 lines
1,017 B
Python
27 lines
1,017 B
Python
# save as data/report.csv
|
|
import os
|
|
import csv
|
|
from typing import List, Dict, Any
|
|
|
|
# target, status, title, description, uri
|
|
|
|
# file path는 'data/report.csv'로 고정
|
|
def save_report(report_data: List[Dict[str, Any]], file_path: str = 'data/report.csv') -> None:
|
|
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
|
|
|
|
|
"""
|
|
Save the report data to a CSV file.
|
|
|
|
:param report_data: List of dictionaries containing report data.
|
|
:param file_path: Path to the CSV file where the report will be saved.
|
|
"""
|
|
fieldnames = ['target', 'status', 'title', 'description', 'uri']
|
|
|
|
with open(file_path, mode='w', newline='', encoding='utf-8') as csvfile:
|
|
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
|
writer.writeheader()
|
|
for row in report_data:
|
|
# Replace actual newlines with literal \n strings
|
|
escaped_row = {k: str(v).replace('\n', '\\n') if v is not None else v for k, v in row.items()}
|
|
writer.writerow(escaped_row)
|