This commit is contained in:
22
main.py
22
main.py
@@ -488,10 +488,10 @@ async def download_all(dates: DownloadRange):
|
|||||||
full_dir_path = os.path.join(DOCUMENTS_DIR, date_path)
|
full_dir_path = os.path.join(DOCUMENTS_DIR, date_path)
|
||||||
logger.info(f"Проверяем путь: {full_dir_path}")
|
logger.info(f"Проверяем путь: {full_dir_path}")
|
||||||
|
|
||||||
# if os.path.exists(full_dir_path):
|
if os.path.exists(full_dir_path):
|
||||||
for file in os.listdir(full_dir_path):
|
for file in os.listdir(full_dir_path):
|
||||||
if file.endswith('.docx'):
|
if file.endswith('.docx'):
|
||||||
all_files.append(os.path.join(full_dir_path, file))
|
all_files.append(os.path.join(full_dir_path, file))
|
||||||
|
|
||||||
current_date += timedelta(days=1)
|
current_date += timedelta(days=1)
|
||||||
|
|
||||||
@@ -501,10 +501,10 @@ async def download_all(dates: DownloadRange):
|
|||||||
if not all_files:
|
if not all_files:
|
||||||
return {"error": "Файлы не найдены за указанный период", "date_start": date_start, "date_finish": date_finish}
|
return {"error": "Файлы не найдены за указанный период", "date_start": date_start, "date_finish": date_finish}
|
||||||
|
|
||||||
# Создаём архив во временной директории
|
# Создаём архив в директории DOCUMENTS_DIR
|
||||||
archive_name = f"documents.zip"
|
archive_name = f"documents_{date_start}_{date_finish}.zip"
|
||||||
archive_path = os.path.join(tempfile.gettempdir(), archive_name)
|
archive_path = os.path.join(DOCUMENTS_DIR, archive_name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
with zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||||
for file_path in all_files:
|
for file_path in all_files:
|
||||||
@@ -514,7 +514,7 @@ async def download_all(dates: DownloadRange):
|
|||||||
return {"error": f"Ошибка создания архива: {e}"}
|
return {"error": f"Ошибка создания архива: {e}"}
|
||||||
|
|
||||||
logger.info(f"Архив создан: {archive_path}")
|
logger.info(f"Архив создан: {archive_path}")
|
||||||
|
|
||||||
# Возвращаем архив
|
# Возвращаем архив
|
||||||
response = FileResponse(
|
response = FileResponse(
|
||||||
path=archive_path,
|
path=archive_path,
|
||||||
@@ -545,5 +545,5 @@ def get_logs():
|
|||||||
lines = file.readlines()[-10:] # последние 10 строк
|
lines = file.readlines()[-10:] # последние 10 строк
|
||||||
return {"logs": lines}
|
return {"logs": lines}
|
||||||
|
|
||||||
# if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# uvicorn.run("main:app", port=8001, reload=True)
|
uvicorn.run("main:app", port=8001, reload=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user