65 lines
2.8 KiB
Python
65 lines
2.8 KiB
Python
import os, json, time, zipfile, shutil, subprocess
|
||
from pathlib import Path
|
||
from pypdf import PdfWriter, PdfReader
|
||
from evidence_analyzer import analyze_evidence
|
||
from pdf_tagger import tag_image_to_pdf
|
||
from gdrive_uploader import upload_gis_archive
|
||
|
||
# --- CONFIG (LEGAL PATHS ONLY) ---
|
||
LOCAL_ARCHIVE = Path("/home/matrixhasyou/domovoy_bot/services/gis_harvester/archive")
|
||
TEMP_DIR = Path("/home/matrixhasyou/domovoy_bot/services/gis_pdf_pipeline/temp")
|
||
OUTPUT_FILE = Path("/home/matrixhasyou/domovoy_bot/services/gis_pdf_pipeline/TOTAL_GIS_ARCHIVE.pdf")
|
||
NAS_LEGAL_PATH = "/volume1/web/legal/gis/TOTAL_GIS_ARCHIVE.pdf"
|
||
NAS_IP = "192.168.10.105"
|
||
|
||
def send_tg(msg):
|
||
subprocess.run(["curl", "-s", "-X", "POST", f"https://api.telegram.org/bot8725618164:AAH1tGalq-pw1l0t4P5c0sdLkCVJdh7IE7M/sendMessage",
|
||
"-d", f"chat_id=197957361&text={msg}&parse_mode=markdown"])
|
||
|
||
def run_pipeline():
|
||
send_tg("🧬 **PDF-КОНВЕЙЕР (LEGAL MODE)**\nНачинаю сборку из /services/gis_harvester/archive...")
|
||
|
||
if TEMP_DIR.exists(): shutil.rmtree(TEMP_DIR)
|
||
TEMP_DIR.mkdir(parents=True, exist_ok=True)
|
||
|
||
writer = PdfWriter()
|
||
cases = sorted([d for d in LOCAL_ARCHIVE.iterdir() if d.is_dir()], reverse=True)
|
||
processed = 0
|
||
|
||
for case in cases:
|
||
try:
|
||
evidence_img = case / "evidence.png"
|
||
if not evidence_img.exists(): continue
|
||
|
||
meta = analyze_evidence(str(evidence_img))
|
||
if not meta or "error" in meta:
|
||
meta = {"number": case.name, "date": "Unknown", "time": "", "status": "Unknown"}
|
||
|
||
case_pdf = TEMP_DIR / f"{case.name}_evidence.pdf"
|
||
tag_image_to_pdf(str(evidence_img), str(case_pdf), meta)
|
||
writer.append(str(case_pdf))
|
||
|
||
zip_path = case / "attachments.zip"
|
||
if zip_path.exists():
|
||
ex_path = TEMP_DIR / case.name
|
||
ex_path.mkdir(parents=True, exist_ok=True)
|
||
with zipfile.ZipFile(zip_path, 'r') as zr: zr.extractall(ex_path)
|
||
for root, dirs, files in os.walk(ex_path):
|
||
for f in files:
|
||
if f.lower().endswith(".pdf"): writer.append(os.path.join(root, f))
|
||
processed += 1
|
||
except Exception as e: print(f"Error on {case.name}: {e}")
|
||
|
||
with open(OUTPUT_FILE, "wb") as f: writer.write(f)
|
||
|
||
# ПУШ НА NAS (ЮРИДИЧЕСКИЙ ПУТЬ)
|
||
with open(OUTPUT_FILE, "rb") as f:
|
||
subprocess.run(["ssh", f"matrixhasyou@{NAS_IP}", f"cat > {NAS_LEGAL_PATH}"], stdin=f)
|
||
|
||
# ПУШ НА DRIVE
|
||
drive_status = upload_gis_archive(str(OUTPUT_FILE))
|
||
|
||
send_tg(f"🏁 **ЮРИДИЧЕСКИЙ PDF ГОТОВ**\n📦 Путь: `/web/legal/gis/`\n☁️ Drive: {drive_status}\n🎯 Дел: {processed}")
|
||
|
||
if __name__ == "__main__":
|
||
run_pipeline()
|