93 lines
4 KiB
Python
93 lines
4 KiB
Python
import json
|
|
import os
|
|
import subprocess
|
|
import time
|
|
import re
|
|
from pathlib import Path
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
# --- CONFIG ---
|
|
QUEUE_FILE = "/app/services/gis_harvester/data/full_queue.json"
|
|
STORAGE_ROOT = Path("/app/services/gis_harvester/archive")
|
|
NAS_TARGET = Path("/app/downloads/nas") # Примонтировано к /mnt/nas/.../gis_archive
|
|
BOT_TOKEN = "8725618164:AAH1tGalq-pw1l0t4P5c0sdLkCVJdh7IE7M"
|
|
CHAT_ID = "197957361"
|
|
|
|
def send_tg_status(msg):
|
|
subprocess.run(["curl", "-s", "-X", "POST", f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage",
|
|
"-d", f"chat_id={CHAT_ID}&text={msg}&parse_mode=markdown"])
|
|
|
|
def run_harvest():
|
|
if not os.path.exists(QUEUE_FILE):
|
|
print("❌ Очередь не найдена!")
|
|
return
|
|
|
|
with open(QUEUE_FILE, "r") as f:
|
|
queue = json.load(f)
|
|
|
|
total = len(queue)
|
|
print(f"[*] Начало жатвы {total} целей...")
|
|
|
|
with sync_playwright() as p:
|
|
try:
|
|
browser = p.chromium.connect_over_cdp("http://127.0.0.1:9222")
|
|
page = browser.contexts[0].pages[0]
|
|
|
|
for index, item in enumerate(queue):
|
|
num = item['number'].replace('/', '_').replace(' ', '_')[:50]
|
|
local_dir = STORAGE_ROOT / num
|
|
nas_dir = NAS_TARGET / num
|
|
|
|
# Пропускаем если уже есть на NAS
|
|
if nas_dir.exists() and (nas_dir / "evidence.png").exists():
|
|
print(f"[-] {num} уже в архиве, пропускаем.")
|
|
continue
|
|
|
|
try:
|
|
print(f"[{index+1}/{total}] Вход в {num}...")
|
|
page.goto("https://my.dom.gosuslugi.ru" + item['href'])
|
|
page.wait_for_load_state("networkidle")
|
|
time.sleep(10)
|
|
|
|
# Скриншот
|
|
local_dir.mkdir(parents=True, exist_ok=True)
|
|
page.screenshot(path=str(local_dir / "evidence.png"), full_page=True)
|
|
|
|
# Скачивание
|
|
download_btn = page.get_by_text("Скачать все").first
|
|
if download_btn.is_visible():
|
|
with page.expect_download(timeout=120000) as download_info:
|
|
download_btn.click()
|
|
download = download_info.value
|
|
zip_path = local_dir / "attachments.zip"
|
|
download.save_as(str(zip_path))
|
|
|
|
# Распаковка
|
|
subprocess.run(["unzip", "-o", str(zip_path), "-d", str(local_dir)])
|
|
|
|
# Копирование в NAS-шару (через маунт докера)
|
|
nas_dir.mkdir(parents=True, exist_ok=True)
|
|
subprocess.run(f"cp -r {local_dir}/* '{nas_dir}/'", shell=True)
|
|
|
|
status = "✅ ZIP + Скрин"
|
|
else:
|
|
nas_dir.mkdir(parents=True, exist_ok=True)
|
|
subprocess.run(f"cp -r {local_dir}/* '{nas_dir}/'", shell=True)
|
|
status = "⚠️ Только скрин (нет вложений)"
|
|
|
|
# Информирование
|
|
bar = "█" * ((index + 1) * 10 // total) + "░" * (10 - ((index + 1) * 10 // total))
|
|
msg = f"🌾 **ЖНЕЦ 4.0: ЖАТВА**\n\n🎯 {item['number'][:50]}\nСтатус: {status}\n\n[{bar}] {index+1}/{total}"
|
|
send_tg_status(msg)
|
|
|
|
except Exception as e:
|
|
print(f"⚠️ Ошибка на {num}: {e}")
|
|
page.goto("https://my.dom.gosuslugi.ru/citizen-cabinet/#!/appeals/applicant/search")
|
|
time.sleep(5)
|
|
|
|
browser.close()
|
|
except Exception as e:
|
|
send_tg_status(f"🚨 КАТАСТРОФА ЖНЕЦА: {str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
run_harvest()
|