From c007a119ab2d797fb0f418150c275accdcab4317 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 7 Apr 2026 09:42:09 +1000 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 6b378b1..41c5e0b 100644 --- a/main.py +++ b/main.py @@ -488,10 +488,10 @@ async def download_all(dates: DownloadRange): full_dir_path = os.path.join(DOCUMENTS_DIR, date_path) logger.info(f"Проверяем путь: {full_dir_path}") - # if os.path.exists(full_dir_path): - for file in os.listdir(full_dir_path): - if file.endswith('.docx'): - all_files.append(os.path.join(full_dir_path, file)) + if os.path.exists(full_dir_path): + for file in os.listdir(full_dir_path): + if file.endswith('.docx'): + all_files.append(os.path.join(full_dir_path, file)) current_date += timedelta(days=1) @@ -501,10 +501,10 @@ async def download_all(dates: DownloadRange): if not all_files: return {"error": "Файлы не найдены за указанный период", "date_start": date_start, "date_finish": date_finish} - # Создаём архив во временной директории - archive_name = f"documents.zip" - archive_path = os.path.join(tempfile.gettempdir(), archive_name) - + # Создаём архив в директории DOCUMENTS_DIR + archive_name = f"documents_{date_start}_{date_finish}.zip" + archive_path = os.path.join(DOCUMENTS_DIR, archive_name) + try: with zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED) as zipf: for file_path in all_files: @@ -514,7 +514,7 @@ async def download_all(dates: DownloadRange): return {"error": f"Ошибка создания архива: {e}"} logger.info(f"Архив создан: {archive_path}") - + # Возвращаем архив response = FileResponse( path=archive_path, @@ -545,5 +545,5 @@ def get_logs(): lines = file.readlines()[-10:] # последние 10 строк return {"logs": lines} -# if __name__ == "__main__": -# uvicorn.run("main:app", port=8001, reload=True) +if __name__ == "__main__": + uvicorn.run("main:app", port=8001, reload=True)