matrx-scraper 0.2.331__py3-none-any.whl → 0.2.332__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -375,6 +375,8 @@ class AnalysisItem(MatrxEntity):
375
375
  published_to_web = BooleanField(null=False)
376
376
  published_to_web_at = DateTimeField()
377
377
  published_to_web_by = UUIDField()
378
+ evidence_kind = TextField(null=False, default='measured')
379
+ tier = TextField()
378
380
  _inverse_foreign_keys: ClassVar[dict[str, dict[str, str]]] = {'analysis_result': {'from_model': 'AnalysisResult', 'from_field': 'item_id', 'referenced_field': 'id', 'related_name': 'analysis_result', 'from_schema': 'web'}, 'finding': {'from_model': 'Finding', 'from_field': 'item_id', 'referenced_field': 'id', 'related_name': 'finding', 'from_schema': 'web'}, 'site_item_config': {'from_model': 'SiteItemConfig', 'from_field': 'item_id', 'referenced_field': 'id', 'related_name': 'site_item_config', 'from_schema': 'web'}}
379
381
  _database = "matrx_web"
380
382
  _table_name = "analysis_item"
@@ -413,9 +413,9 @@ def _audit_tree(tree: HTMLParser, base_url: str) -> SeoAuditResult:
413
413
  image_inventory, resources = _extract_page_resources(tree, base_url)
414
414
  _append_structured_resources(resources, structured.to_dict(), base_url)
415
415
  images_total = len(tree.css("img"))
416
- # `alt=""` is the HTML-sanctioned way to mark a decorative image; only an
417
- # image with NO alt attribute at all is missing one.
418
- images_missing_alt = sum(1 for img in tree.css("img") if "alt" not in img.attributes)
416
+ images_missing_alt = sum(
417
+ 1 for img in tree.css("img") if not (img.attributes.get("alt") or "").strip()
418
+ )
419
419
  page_identity = _extract_page_identity(
420
420
  tree,
421
421
  base_url,
@@ -761,7 +761,8 @@ def _extract_page_resources(
761
761
  "picture_formats": _picture_source_formats(img, base_url),
762
762
  "picture_sources": _picture_source_urls(img, base_url),
763
763
  "sizes": attrs.get("sizes"),
764
- "alt": attrs.get("alt"),
764
+ # selectolax reports `alt=""` as None; presence of the attribute is the signal.
765
+ "alt": (attrs.get("alt") or "") if "alt" in attrs else None,
765
766
  "width": _number_attribute(attrs.get("width")),
766
767
  "height": _number_attribute(attrs.get("height")),
767
768
  "loading": attrs.get("loading"),
@@ -348,6 +348,90 @@ GSC_HEALTHY_SCORE = 100
348
348
  # Evidence structs
349
349
 
350
350
 
351
+ def _is_homepage(url: str | None) -> bool:
352
+ """The site's root page — where a failure costs the most."""
353
+ from urllib.parse import urlsplit
354
+
355
+ if not url:
356
+ return False
357
+ parts = urlsplit(url)
358
+ return parts.path in ("", "/") and not parts.query
359
+
360
+
361
+ #: A stored crawl status is evidence about the moment of the crawl. Pages it
362
+ #: says were failing are asked again before analysis calls them broken (fact
363
+ #: before opinion, 2026-10-05: four "500" pages on a sample site answered 200).
364
+ LIVE_RECHECK_LIMIT = 200
365
+ LIVE_RECHECK_TIMEOUT_SECONDS = 180
366
+ LIVE_RECHECKED_CHECKS = frozenset({"server_error_5xx", "broken_page_4xx"})
367
+
368
+
369
+ async def recheck_failing_statuses(
370
+ facts_list: list[PageFacts],
371
+ *,
372
+ verifier: Any | None = None,
373
+ limit: int = LIVE_RECHECK_LIMIT,
374
+ ) -> dict[str, dict[str, Any]]:
375
+ """Ask every page the crawl recorded as failing (0, 4xx, 5xx) again, now.
376
+
377
+ A page that answers below 400 now gets its CURRENT status as evidence (the
378
+ checks then pass it); one that still fails keeps failing with today's
379
+ confirmation; one we could not reach keeps the crawl's status — no answer
380
+ is never a recovery. Returns ``page_id -> {crawl_status, live_status,
381
+ checked_at, error}`` for the result metadata.
382
+ """
383
+ from matrx_scraper.utils.url import public_http_client
384
+ from matrx_scraper.web_crawl.url_verify import (
385
+ REQUEST_TIMEOUT_SECONDS,
386
+ USER_AGENT,
387
+ PoliteVerifier,
388
+ )
389
+
390
+ failing = [
391
+ f
392
+ for f in facts_list
393
+ if f.url and f.http_status is not None and (f.http_status == 0 or f.http_status >= 400)
394
+ ]
395
+ # The homepage first, then the shallowest pages: when a site has more
396
+ # failing pages than the cap, the ones that matter most are asked again.
397
+ failing.sort(key=lambda f: (not _is_homepage(f.url), len(str(f.url))))
398
+ targets = failing[:limit]
399
+ if not targets:
400
+ return {}
401
+ client = None
402
+ if verifier is None:
403
+ client = public_http_client(
404
+ timeout=REQUEST_TIMEOUT_SECONDS,
405
+ follow_redirects=True,
406
+ headers={"User-Agent": USER_AGENT},
407
+ )
408
+ verifier = PoliteVerifier(client)
409
+ checked_at = datetime.now(UTC).isoformat()
410
+ rechecks: dict[str, dict[str, Any]] = {}
411
+
412
+ async def one(facts: PageFacts) -> None:
413
+ outcome = await verifier.verify(str(facts.url))
414
+ crawl_status = facts.http_status
415
+ live = outcome.http_status
416
+ rechecks[str(facts.page_id)] = {
417
+ "crawl_status": crawl_status,
418
+ "live_status": live,
419
+ "checked_at": checked_at,
420
+ "error": outcome.error,
421
+ }
422
+ # Any real answer is the current fact (500 then 404 is a 404 now);
423
+ # no answer keeps the crawl's record.
424
+ if live and live > 0:
425
+ facts.http_status = live
426
+
427
+ try:
428
+ await asyncio.gather(*(one(f) for f in targets))
429
+ finally:
430
+ if client is not None:
431
+ await client.aclose()
432
+ return rechecks
433
+
434
+
351
435
  @dataclass
352
436
  class PageFacts(PageEvidence):
353
437
  """Per-page evidence from the latest accepted snapshot.
@@ -3255,6 +3339,17 @@ async def analyze_site_pages(
3255
3339
  await report("Loading page evidence…")
3256
3340
  async with _timed("page_evidence"):
3257
3341
  facts_list, aggregates = await _load_page_facts(site_id, summary, str(site.root_url))
3342
+ async with _timed("live_status_recheck"):
3343
+ try:
3344
+ status_rechecks = await asyncio.wait_for(
3345
+ recheck_failing_statuses(facts_list), timeout=LIVE_RECHECK_TIMEOUT_SECONDS
3346
+ )
3347
+ except Exception as exc: # the stored evidence still stands; say so
3348
+ logger.exception("live status recheck failed for site %s", site_id)
3349
+ summary.errors.append(
3350
+ f"Pages the crawl saw failing could not be checked again: {type(exc).__name__}: {exc}"
3351
+ )
3352
+ status_rechecks = {}
3258
3353
  # Google's own numbers. A site with no Search Console property is the
3259
3354
  # ordinary case, not an error: the checks answer `n_a` naming that, and the
3260
3355
  # rest of the sweep is untouched.
@@ -3321,8 +3416,12 @@ async def analyze_site_pages(
3321
3416
  outcome = CheckOutcome(
3322
3417
  "error", None, f"Check crashed: {type(exc).__name__}: {exc}"
3323
3418
  )
3324
- severity = severity_for(item, outcome.score)
3419
+ severity = severity_for(
3420
+ item, outcome.score, on_homepage=_is_homepage(facts.url)
3421
+ )
3325
3422
  metadata = _result_metadata(outcome, item.key)
3423
+ if item_key in LIVE_RECHECKED_CHECKS and facts.page_id in status_rechecks:
3424
+ metadata["live_recheck"] = status_rechecks[facts.page_id]
3326
3425
  rows.append(
3327
3426
  {
3328
3427
  "organization_id": organization_id,
@@ -45,12 +45,23 @@ _RESULT_INSERT_BATCH = 500
45
45
  _EPOCH = datetime.min.replace(tzinfo=UTC)
46
46
 
47
47
 
48
- def severity_for(item: WebAnalysisItem, score: int | None) -> str:
49
- """Map a score onto the catalogue row's own severity bands.
48
+ SEVERITY_ORDER = ("info", "low", "med", "high", "critical")
50
49
 
51
- The item row owns the bands — a provider never invents severity. A scoreless
52
- outcome (`n_a`/`error`) is `info`: it carries no judgement about the page.
53
- """
50
+
51
+ def _step(severity: str, by: int) -> str:
52
+ index = SEVERITY_ORDER.index(severity) if severity in SEVERITY_ORDER else 0
53
+ return SEVERITY_ORDER[max(0, min(len(SEVERITY_ORDER) - 1, index + by))]
54
+
55
+
56
+ def _cap(severity: str, ceiling: str) -> str:
57
+ if severity not in SEVERITY_ORDER:
58
+ return ceiling
59
+ return severity if SEVERITY_ORDER.index(severity) <= SEVERITY_ORDER.index(ceiling) else ceiling
60
+
61
+
62
+ def band_severity(item: WebAnalysisItem, score: int | None) -> str:
63
+ """The catalogue row's own band for a score. A scoreless outcome
64
+ (`n_a`/`error`) is `info`: it carries no judgement about the page."""
54
65
  if score is None:
55
66
  return "info"
56
67
  bands = ((item.severity_map or {}).get("bands")) or []
@@ -63,6 +74,41 @@ def severity_for(item: WebAnalysisItem, score: int | None) -> str:
63
74
  return "info"
64
75
 
65
76
 
77
+ def severity_for(item: WebAnalysisItem, score: int | None, *, on_homepage: bool = False) -> str:
78
+ """Severity = the check's band, shaped by its TIER (Arman's 2026-10-05
79
+ check-tier rulings, ``web.analysis_item.tier``) and where it failed.
80
+
81
+ * A (blocks being found): one step up, never below ``high`` once failing.
82
+ * B (hurts rankings): the band, capped at ``high``.
83
+ * C (polish): the band, capped at ``low``.
84
+ * D (AI opinion): always ``info`` — an opinion never escalates.
85
+ * A failure on the homepage moves up one more step (except tier D).
86
+ A passing or scoreless result stays ``info`` whatever the tier.
87
+ Plan: common-docs/systems/marketing/seo/projects/fact-before-opinion/REGISTER.md R-04.
88
+ """
89
+ base = band_severity(item, score)
90
+ if base == "info":
91
+ return "info"
92
+ tier = getattr(item, "tier", None)
93
+ if tier == "D":
94
+ return "info"
95
+ if tier == "A":
96
+ severity = _step(base, 1)
97
+ if SEVERITY_ORDER.index(severity) < SEVERITY_ORDER.index("high"):
98
+ severity = "high"
99
+ elif tier == "B":
100
+ severity = _cap(base, "high")
101
+ elif tier == "C":
102
+ severity = _cap(base, "low")
103
+ else:
104
+ severity = base
105
+ if on_homepage:
106
+ severity = _step(severity, 1)
107
+ if tier == "C":
108
+ severity = _cap(severity, "med")
109
+ return severity
110
+
111
+
66
112
  async def insert_results(rows: list[dict]) -> list[WebAnalysisResult]:
67
113
  """Insert immutable result rows in batches, refusing to under-report."""
68
114
  created: list[WebAnalysisResult] = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: matrx-scraper
3
- Version: 0.2.331
3
+ Version: 0.2.332
4
4
  Summary: Web scraping engine, HTML parsing, and search integration for the Matrx ecosystem
5
5
  Project-URL: Homepage, https://github.com/AI-Matrix-Engine/aidream-current
6
6
  Project-URL: Repository, https://github.com/AI-Matrix-Engine/aidream-current
@@ -40,7 +40,7 @@ Requires-Dist: datasketch>=1.6; extra == 'all'
40
40
  Requires-Dist: extruct>=0.18; extra == 'all'
41
41
  Requires-Dist: fastapi>=0.115; extra == 'all'
42
42
  Requires-Dist: matrx-connect>=0.1.183; extra == 'all'
43
- Requires-Dist: matrx-graph>=0.2.260; extra == 'all'
43
+ Requires-Dist: matrx-graph>=0.2.262; extra == 'all'
44
44
  Requires-Dist: matrx-orm>=3.1.219; extra == 'all'
45
45
  Requires-Dist: matrx-runtime>=0.0.155; extra == 'all'
46
46
  Requires-Dist: pillow>=11.0; extra == 'all'
@@ -68,7 +68,7 @@ Requires-Dist: simhash>=2.1; extra == 'dedup'
68
68
  Provides-Extra: durable
69
69
  Requires-Dist: matrx-runtime>=0.0.155; extra == 'durable'
70
70
  Provides-Extra: graph
71
- Requires-Dist: matrx-graph>=0.2.260; extra == 'graph'
71
+ Requires-Dist: matrx-graph>=0.2.262; extra == 'graph'
72
72
  Provides-Extra: metadata
73
73
  Requires-Dist: extruct>=0.18; extra == 'metadata'
74
74
  Provides-Extra: ocr
@@ -100,7 +100,7 @@ Requires-Dist: datasketch>=1.6; extra == 'standalone'
100
100
  Requires-Dist: extruct>=0.18; extra == 'standalone'
101
101
  Requires-Dist: fastapi>=0.115; extra == 'standalone'
102
102
  Requires-Dist: matrx-connect>=0.1.183; extra == 'standalone'
103
- Requires-Dist: matrx-graph>=0.2.260; extra == 'standalone'
103
+ Requires-Dist: matrx-graph>=0.2.262; extra == 'standalone'
104
104
  Requires-Dist: matrx-orm>=3.1.219; extra == 'standalone'
105
105
  Requires-Dist: matrx-runtime>=0.0.155; extra == 'standalone'
106
106
  Requires-Dist: pillow>=11.0; extra == 'standalone'
@@ -38,7 +38,7 @@ matrx_scraper/sampling.py,sha256=PGoUI9mUFMgknde90hlIHLfSXhoESVaSkHqQWVLFyOY,232
38
38
  matrx_scraper/scrape_options.py,sha256=0wKRUGGvyOMEDlPb3I4-Sir50DtBdQqD3ciJg-a0R0g,2266
39
39
  matrx_scraper/scraper.py,sha256=LLkdnbh9ix9uNpziYQ8P532MNz5yjeiW8vQyuSR2ZDg,64703
40
40
  matrx_scraper/screenshot_dimensions.py,sha256=vMsiPieq0qykrL6QTIgGgRUz2xlcWzcCElikFQN5r84,1054
41
- matrx_scraper/seo_audit.py,sha256=jBr9ZyDPXqyXL5hpMkRSnn-WEiJvthkITjBg3ArcH6A,196223
41
+ matrx_scraper/seo_audit.py,sha256=XgLim975lcGmRJD1lJHX-3HN3s1YjM8N8udvXgt5ehg,196248
42
42
  matrx_scraper/service.py,sha256=GgQhjE_T6NfN2v-lF8PEXBSH_UWNXmiV42YGpu2nBlk,28625
43
43
  matrx_scraper/sitemaps.py,sha256=5elyvYH-bwoGUbT2tg2aC1mcGhT6bPrZPAmj2_SN4b0,12680
44
44
  matrx_scraper/source_landing.py,sha256=5xh0Os6BhfBNsH6ZCwBhMSk8sfeCjqcHuW0X_QRTr3c,16966
@@ -137,7 +137,7 @@ matrx_scraper/db/__init__.py,sha256=kZmTLMcei8dpD9-VbDnU8dVSaVM30qItI1ne5W58mL4,
137
137
  matrx_scraper/db/_config.py,sha256=iqoWNkYjU2GfTIOomJqD12Ob8H11WqOBHCqsDgIkVXc,1192
138
138
  matrx_scraper/db/models_scraper.py,sha256=xkTIb5bS3B4mgQltn4zdyokfXtsJ_0NWj9usVbFpz5Y,9565
139
139
  matrx_scraper/db/models_seo_host.py,sha256=HMssIt43qkP22tLgY1yjufnCDtBh_fgUx9zfvNRh4Hk,2418
140
- matrx_scraper/db/models_web.py,sha256=j-fJJogqi0JNzVeixodl0YYZruioBIYpyzt5eltbPtU,77787
140
+ matrx_scraper/db/models_web.py,sha256=RmyZPZFMqMuWq1IfmNSDwfuh0bp5qHBjng9nBmQyDzE,77872
141
141
  matrx_scraper/db/web.py,sha256=ydatMV6Ix9eYSGqLzEG-iSx7EE2HH8jgd1o-DBaWpb8,3181
142
142
  matrx_scraper/features/__init__.py,sha256=CXsDlz_kB2AqzoTd640tBt5Y0QUJ5Tox7sqWJ2O_7cI,776
143
143
  matrx_scraper/features/extensions.py,sha256=IOS5_T7-j9slFiSWT9LOTmy7-vhrPxKibGmqOe5IJHg,1954
@@ -190,8 +190,8 @@ matrx_scraper/utils/url-identity-rules.json,sha256=CO7FW52wMT00uwVt_xE_0bbOuREcx
190
190
  matrx_scraper/utils/url.py,sha256=YLgBhmWIKcLN2VtfHVTenNrkElMQ0oNlno7p5RJy9S0,15994
191
191
  matrx_scraper/web_crawl/FEATURE.md,sha256=V4MZ9jK8u4mJvplQWvnmry03r_Wu5c61grf7cWqEnt4,160516
192
192
  matrx_scraper/web_crawl/__init__.py,sha256=UErZtkvHzW8_3A0FT20b6Rlz11M2u_tYncIlvL7XwJk,364
193
- matrx_scraper/web_crawl/analysis.py,sha256=y7aevqWycgjrNo6vj3qRF9X86HAGQCDyqypwsWIbQhU,146228
194
- matrx_scraper/web_crawl/analysis_write.py,sha256=F0ySMM6eMa2fM8QxAxiiVun_bGeA0QDyhHB_0WRJTSI,11064
193
+ matrx_scraper/web_crawl/analysis.py,sha256=KCYURWg_ygVGnA-R3swElZXqTyZkNMFRURWibAKqlpg,150025
194
+ matrx_scraper/web_crawl/analysis_write.py,sha256=ZLp9GuoF5V7k9WTIGL5qep0QTa6y2oDAwoeChKXYOHs,12805
195
195
  matrx_scraper/web_crawl/broker.py,sha256=W5XeQ8EayLcD_wPRYztTdn2XgPdWwwK95VGt9IgRJPo,3900
196
196
  matrx_scraper/web_crawl/candidates.py,sha256=N1DG0-az86aZNArGqjkUVLpClbMwhAaYNHefmgUhJOo,14971
197
197
  matrx_scraper/web_crawl/contracts.py,sha256=9hlUViEa0d_V2qC1w52siTcMF34hHVureJ1VlGSozEg,30252
@@ -215,7 +215,7 @@ matrx_scraper/web_crawl/sitemap_sync.py,sha256=28maGl5pks4nKCu1ukmTiW96mquD6txP5
215
215
  matrx_scraper/web_crawl/upsert_rows.py,sha256=GW_YaotbXdPpoHJymrKXMB6OzU6t0hIgm8vrcOcP5FY,1972
216
216
  matrx_scraper/web_crawl/url_identity.py,sha256=w-slLxOL3oyKRF5rp4ccMxYAEEyjYQOt4ubbLLjWQII,47371
217
217
  matrx_scraper/web_crawl/url_verify.py,sha256=1h1XAOMvYrPUvqxVWixJmpN4MoFKq7zJgSES8klTknI,33106
218
- matrx_scraper-0.2.331.dist-info/METADATA,sha256=S-EoHUgWINJpjl_Ufjbv9wWm32fNUB-c05mA0JTVwFA,12681
219
- matrx_scraper-0.2.331.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
220
- matrx_scraper-0.2.331.dist-info/entry_points.txt,sha256=sNKYpYDDn8F4xwUBB3fC21R0nQpZEYLV_c00D787Z0I,69
221
- matrx_scraper-0.2.331.dist-info/RECORD,,
218
+ matrx_scraper-0.2.332.dist-info/METADATA,sha256=4v6GN8--TB5kHLIsNZglhry_hAo3zuxOyX4zSNKiErQ,12681
219
+ matrx_scraper-0.2.332.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
220
+ matrx_scraper-0.2.332.dist-info/entry_points.txt,sha256=sNKYpYDDn8F4xwUBB3fC21R0nQpZEYLV_c00D787Z0I,69
221
+ matrx_scraper-0.2.332.dist-info/RECORD,,