#!/usr/bin/env python3 """ Парсер новостей с mont.ru → публикует в ZKART БД. Запуск: python3 mont_scraper.py [--all10] """ import re, os, sys, secrets, datetime, sqlite3, time, json from urllib.request import urlopen, Request, build_opener, HTTPCookieProcessor from http.cookiejar import CookieJar from urllib.parse import urlencode, urlparse from html import unescape DB_PATH = "/home/ruslan/docker/ZKART#/matrix.db" IMG_DIR = "/home/ruslan/docker/ZKART#/static/news_images" BASE_URL = "https://www.mont.ru" LIST_URL = "https://www.mont.ru/ru-ru/news?period=1" SITE_BASE = "https://maps.4mont.ru" TG_TOKEN = "8181219074:AAGvqWqb6t10YP4xpMOQnBq_6LrUqAFm5hM" TG_CHAT_ID = "54986411" MONT_EMAIL = "rgalyaviev@mont.com" MONT_PASS = "utOgbZ09mont" HEADERS = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36", "Accept": "text/html,application/xhtml+xml,*/*;q=0.9"} os.makedirs(IMG_DIR, exist_ok=True) # ── Auth ────────────────────────────────────────────────────────────────────── def make_authenticated_opener() -> build_opener: """Login to mont.ru via OIDC and return an opener with auth cookies.""" jar = CookieJar() opener = build_opener(HTTPCookieProcessor(jar)) # Step 1: GET login → redirected to passport.mont.ru req = Request(f"{BASE_URL}/ru-ru/account/login", headers=HEADERS) with opener.open(req, timeout=20) as r: html = r.read().decode("utf-8", errors="replace") login_url = r.url form_action = re.search(r'