feat(ext): Фаза 4/5 — охват всех источников/документов + все регионы
fgis_client: opendata_list/meta/download (15 датасетов: КСР/ФСНБ/СПСРП/оплата труда/9 ПССР), bim_leaf_docs (дерево писем-индексов), download_by_guid, all_subject_ids. xsd_client: скрейп .zip-схем экспертизы (html.parser, fail-loud на 0 ссылок). ext_pull: pull_opendata/bim/xsd, --source opendata/bim/xsd/all-sources, --regions all (все 86). ext_check: check_opendata (lastChangeDate)/check_bim(guid)/check_xsd(ссылки) + режим all-regions — чекер мониторит ВСЁ. 10 новых тестов.
This commit is contained in:
+70
-2
@@ -23,10 +23,75 @@ import pravo_client as pc
|
||||
|
||||
|
||||
def _regions() -> list[int]:
|
||||
raw = os.environ.get("EXT_REGIONS", "")
|
||||
raw = os.environ.get("EXT_REGIONS", "").strip()
|
||||
if raw.lower() == "all":
|
||||
try:
|
||||
return [s["id"] for s in fc.country_subjects()]
|
||||
except ext_fetch.FetchError:
|
||||
return []
|
||||
return [int(x) for x in raw.replace(";", ",").split(",") if x.strip().isdigit()]
|
||||
|
||||
|
||||
def check_opendata(seen: dict, *, client=None) -> tuple[list[dict], dict]:
|
||||
"""Обновлённые датасеты открытых данных (КСР/ФСНБ/СПСРП/оплата труда/ПССР) по lastChangeDate."""
|
||||
prev = seen.get("opendata_lastchange", {})
|
||||
try:
|
||||
datasets = fc.opendata_list(client=client)
|
||||
except ext_fetch.FetchError as e:
|
||||
return [{"source": "opendata", "level": "problem", "message": f"OpenData недоступен: {e}"}], seen
|
||||
findings = []
|
||||
for ds in datasets:
|
||||
did = str(ds["id"])
|
||||
lc = ds.get("lastChangeDate")
|
||||
if prev.get(did) != lc:
|
||||
findings.append({
|
||||
"source": "fgis_opendata", "level": "update",
|
||||
"message": f"Обновлён датасет «{ds.get('datasetName')}» (изм. {lc})",
|
||||
"action": f"python3 ext_pull.py --source opendata --dataset {ds['id']}",
|
||||
})
|
||||
prev[did] = lc
|
||||
seen["opendata_lastchange"] = prev
|
||||
return findings, seen
|
||||
|
||||
|
||||
def check_bim(seen: dict, *, client=None) -> tuple[list[dict], dict]:
|
||||
"""Новые письма-индексы (БИМ) — новые guid листовых документов дерева."""
|
||||
seen_g = set(seen.get("bim_guids", []))
|
||||
try:
|
||||
docs = fc.bim_leaf_docs(client=client)
|
||||
except ext_fetch.FetchError as e:
|
||||
return [{"source": "bim", "level": "problem", "message": f"БИМ-письма недоступны: {e}"}], seen
|
||||
findings = []
|
||||
for d in docs:
|
||||
if d["guid"] not in seen_g:
|
||||
findings.append({"source": "fgis_bim", "level": "update",
|
||||
"message": f"Новое письмо-индекс: {d.get('name') or d['guid']}",
|
||||
"action": "python3 ext_pull.py --source bim"})
|
||||
seen_g.add(d["guid"])
|
||||
seen["bim_guids"] = sorted(seen_g)[-2000:]
|
||||
return findings, seen
|
||||
|
||||
|
||||
def check_xsd(seen: dict, *, client=None) -> tuple[list[dict], dict]:
|
||||
"""Новые/изменённые пакеты XSD-схем экспертизы (по списку ссылок)."""
|
||||
import xsd_client
|
||||
seen_l = set(seen.get("xsd_links", []))
|
||||
try:
|
||||
links = xsd_client.schema_links(client=client)
|
||||
except ext_fetch.FetchError as e:
|
||||
return [{"source": "xsd", "level": "problem", "message": f"XSD-схемы: {e}"}], seen
|
||||
findings = []
|
||||
for href in links:
|
||||
if href not in seen_l:
|
||||
findings.append({"source": "xsd_schema", "level": "update",
|
||||
"message": f"Новый/изменённый пакет схем: {xsd_client._fname(href)}. "
|
||||
f"NB: вступает в силу через ~3 мес после публикации.",
|
||||
"action": "python3 ext_pull.py --source xsd"})
|
||||
seen_l.add(href)
|
||||
seen["xsd_links"] = sorted(seen_l)
|
||||
return findings, seen
|
||||
|
||||
|
||||
def check_fgis(regions: list[int], seen: dict, *, client=None) -> tuple[list[dict], dict]:
|
||||
"""Новый период по каждой зоне сконфигурированных регионов. Дедуп через seen."""
|
||||
findings: list[dict] = []
|
||||
@@ -153,7 +218,10 @@ def run_check(regions: list[int] | None = None, *, notify: bool = True) -> dict:
|
||||
"message": "EXT_REGIONS не задан — ФГИС не мониторится (проверяются только приказы)"})
|
||||
f_fgis, seen = check_fgis(regions, seen)
|
||||
f_pravo, seen = check_pravo(seen)
|
||||
findings += f_fgis + f_pravo
|
||||
f_od, seen = check_opendata(seen)
|
||||
f_bim, seen = check_bim(seen)
|
||||
f_xsd, seen = check_xsd(seen)
|
||||
findings += f_fgis + f_pravo + f_od + f_bim + f_xsd
|
||||
_write_report(findings, regions)
|
||||
|
||||
updates = [f for f in findings if f["level"] in ("update", "problem")]
|
||||
|
||||
Reference in New Issue
Block a user