mirror of
https://github.com/j93es/oauth-backend.git
synced 2026-06-04 09:21:52 +09:00
[Add] csrf 포팅
This commit is contained in:
parent
c0c6743423
commit
a5186a7e44
4 changed files with 210 additions and 19 deletions
|
|
@ -1,23 +1,28 @@
|
|||
# save as data/report.csv
|
||||
import csv
|
||||
import os
|
||||
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:
|
||||
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.
|
||||
report_data 안의 각 레포트를 한 줄씩 CSV에 추가로 저장합니다.
|
||||
파일이 없으면 헤더를 먼저 쓰고, 있으면 레코드만 이어서 씁니다.
|
||||
"""
|
||||
fieldnames = ['target', 'status', 'title', 'description', 'uri']
|
||||
|
||||
with open(file_path, mode='w', newline='', encoding='utf-8') as csvfile:
|
||||
file_exists = os.path.exists(file_path)
|
||||
|
||||
with open(file_path, mode='a', newline='', encoding='utf-8') as csvfile:
|
||||
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
# 파일이 없던 새로 만들 때만 헤더 작성
|
||||
if not file_exists:
|
||||
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)
|
||||
# None 방지 & 줄바꿈 이스케이프
|
||||
escaped = {
|
||||
k: str(v).replace('\n', '\\n') if v is not None else ''
|
||||
for k, v in row.items()
|
||||
}
|
||||
writer.writerow(escaped)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue