Добавлена функция save_report

This commit is contained in:
Антон Репин 2026-05-07 13:24:09 +03:00
parent 794284aa29
commit abecc37deb

View File

@ -135,3 +135,18 @@ def generate_report(stats: dict) -> str:
report_lines.append("=" * 50)
return "\n".join(report_lines)
# 10. Сохранение отчета в файл
def save_report(filepath: str, report_text: str) -> bool:
"""
Сохраняет отчет в файл. Возвращает True при успехе.
"""
try:
os.makedirs(os.path.dirname(filepath), exist_ok=True)
with open(filepath, 'w', encoding='utf-8') as file:
file.write(report_text)
return True
except Exception as e:
print(f"Ошибка при сохранении отчета: {e}")
return False