feat: Add consolidation of all appeals to SUD_CABINET_ALL.pdf and GDrive upload
This commit is contained in:
parent
6ddd33be33
commit
9a143c1ef0
1 changed files with 31 additions and 0 deletions
|
|
@ -139,6 +139,37 @@ def compile_appeals():
|
||||||
log.error(f"Failed to write compiled PDF for {appeal_id}: {e}")
|
log.error(f"Failed to write compiled PDF for {appeal_id}: {e}")
|
||||||
send_tg(f"❌ **Ошибка сборки обращения {appeal_id}**: {e}")
|
send_tg(f"❌ **Ошибка сборки обращения {appeal_id}**: {e}")
|
||||||
|
|
||||||
|
# Compile consolidated master PDF of all appeals
|
||||||
|
if processed > 0:
|
||||||
|
master_writer = PdfWriter()
|
||||||
|
compiled_pdfs = sorted(list(OUTPUT_DIR.glob("SUD_APPEAL_*.pdf")))
|
||||||
|
log.info(f"Consolidating {len(compiled_pdfs)} appeal PDFs into SUD_CABINET_ALL.pdf...")
|
||||||
|
for pdf_file in compiled_pdfs:
|
||||||
|
if pdf_file.name == "SUD_CABINET_ALL.pdf":
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
master_writer.append(str(pdf_file))
|
||||||
|
except Exception as e:
|
||||||
|
log.error(f"Failed to append to master PDF {pdf_file.name}: {e}")
|
||||||
|
|
||||||
|
master_pdf_path = OUTPUT_DIR / "SUD_CABINET_ALL.pdf"
|
||||||
|
try:
|
||||||
|
with open(master_pdf_path, "wb") as out_f:
|
||||||
|
master_writer.write(out_f)
|
||||||
|
log.info("Successfully compiled consolidated master PDF: SUD_CABINET_ALL.pdf")
|
||||||
|
|
||||||
|
# Upload consolidated PDF to GDrive
|
||||||
|
drive_status = "не настроен"
|
||||||
|
if gdrive:
|
||||||
|
try:
|
||||||
|
drive_status = gdrive.upload_or_update(str(master_pdf_path), "SUD_CABINET_ALL.pdf")
|
||||||
|
except Exception as e:
|
||||||
|
drive_status = f"ошибка GDrive: {e}"
|
||||||
|
send_tg(f"☁️ **Сводный файл ГАС Правосудие (SUD_CABINET_ALL.pdf) обновлен**\nGDrive: `{drive_status}`")
|
||||||
|
except Exception as e:
|
||||||
|
log.error(f"Failed to create master PDF: {e}")
|
||||||
|
send_tg(f"❌ **Ошибка создания сводного PDF**: {e}")
|
||||||
|
|
||||||
send_tg(f"🏁 **Компиляция судебных дел завершена!**\nСобрано обращений: {processed}")
|
send_tg(f"🏁 **Компиляция судебных дел завершена!**\nСобрано обращений: {processed}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue