뭐 대충했어요

This commit is contained in:
imnyang 2025-06-07 15:12:15 +09:00
commit 5f84d24973
5 changed files with 138 additions and 29 deletions

23
lib/report.py Normal file
View file

@ -0,0 +1,23 @@
# save as data/report.csv
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:
"""
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)

32
lib/target.py Normal file
View file

@ -0,0 +1,32 @@
# save ./data/target.temp file as domain string
import os
def save(target: str, file_path: str = "./data/target.dump") -> None:
"""
Save the target domain to a temporary file.
:param target: Target domain to be saved.
"""
# Create directory if it doesn't exist
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, 'w', encoding='utf-8') as f:
f.write(target)
print(f"Target saved to {file_path}") # Debug message
def load(file_path: str = "./data/target.dump") -> str:
"""
Load the target domain from a temporary file.
:return: Target domain string.
"""
if not os.path.exists(file_path):
print(f"[ERROR] Target file {file_path} does not exist.")
return ""
with open(file_path, 'r', encoding='utf-8') as f:
target = f.read().strip()
print(f"Loaded target from {file_path}: {target}") # Debug message
return target