-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_report.py
More file actions
27 lines (19 loc) · 866 Bytes
/
save_report.py
File metadata and controls
27 lines (19 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import csv
from logger_config import logger
from normaliz_path import normalaiz
def save_report(report_path: str, report: list[dict]):
"""Сохраняем отчет"""
if not report_path:
logger.warning("Нет пути для сохранения отчета")
report_path = "reports/average-rating.csv"
else:
report_path = normalaiz(report_path)
report_path = f"reports/{report_path}"
try:
with open(report_path, "w", newline='', encoding="utf-8") as file:
writer = csv.DictWriter(file, fieldnames=["brand", "rating"])
writer.writeheader()
writer.writerows(report)
logger.info(f"Отчет сохранен ✅: {report_path}")
except Exception as e:
logger.error(f"Не удалось сохранить отчет {report_path}: {e}")