From 9a143c1ef07584dc0afb6194a1e66a8b9bb7fe36 Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 3 Jul 2026 15:02:32 +0400 Subject: [PATCH] feat: Add consolidation of all appeals to SUD_CABINET_ALL.pdf and GDrive upload --- scraper_gis/sudrf_pdf_compiler.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scraper_gis/sudrf_pdf_compiler.py b/scraper_gis/sudrf_pdf_compiler.py index 81bc00b..9d7d557 100644 --- a/scraper_gis/sudrf_pdf_compiler.py +++ b/scraper_gis/sudrf_pdf_compiler.py @@ -139,6 +139,37 @@ def compile_appeals(): log.error(f"Failed to write compiled PDF for {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}") if __name__ == "__main__":