omnirank 0.5.0__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.
Files changed (183) hide show
  1. omnirank/__init__.py +14 -0
  2. omnirank/__main__.py +6 -0
  3. omnirank/adapters/__init__.py +202 -0
  4. omnirank/adapters/astro.py +338 -0
  5. omnirank/adapters/base.py +372 -0
  6. omnirank/adapters/html.py +561 -0
  7. omnirank/adapters/jsx.py +340 -0
  8. omnirank/adapters/nextjs.py +692 -0
  9. omnirank/aeo/__init__.py +9 -0
  10. omnirank/aeo/extract.py +383 -0
  11. omnirank/aeo/propose.py +84 -0
  12. omnirank/aeo/rules.py +964 -0
  13. omnirank/aeo/runner.py +148 -0
  14. omnirank/applicability.py +98 -0
  15. omnirank/apply/__init__.py +23 -0
  16. omnirank/apply/engine.py +1254 -0
  17. omnirank/apply/journal.py +139 -0
  18. omnirank/apply/patch.py +144 -0
  19. omnirank/audit.py +185 -0
  20. omnirank/bands.py +106 -0
  21. omnirank/brief/__init__.py +0 -0
  22. omnirank/brief/analyze.py +197 -0
  23. omnirank/brief/constants.py +89 -0
  24. omnirank/brief/cost.py +62 -0
  25. omnirank/brief/egress.py +23 -0
  26. omnirank/brief/fetchpages.py +239 -0
  27. omnirank/brief/render.py +151 -0
  28. omnirank/brief/runner.py +369 -0
  29. omnirank/brief/serp.py +274 -0
  30. omnirank/brief/text.py +181 -0
  31. omnirank/cli.py +844 -0
  32. omnirank/clock.py +22 -0
  33. omnirank/cms/__init__.py +1 -0
  34. omnirank/cms/runner.py +170 -0
  35. omnirank/cms/wordpress.py +495 -0
  36. omnirank/cms/wordpress_apply.py +508 -0
  37. omnirank/cms/wordpress_plan.py +280 -0
  38. omnirank/config.py +81 -0
  39. omnirank/connect/__init__.py +4 -0
  40. omnirank/connect/bing.py +284 -0
  41. omnirank/connect/cloud_setup.py +43 -0
  42. omnirank/connect/confirm.py +242 -0
  43. omnirank/connect/constants.py +226 -0
  44. omnirank/connect/doctor.py +270 -0
  45. omnirank/connect/ga4.py +749 -0
  46. omnirank/connect/ga4_ai.py +123 -0
  47. omnirank/connect/google_auth.py +657 -0
  48. omnirank/connect/gsc.py +630 -0
  49. omnirank/connect/gsc_reports.py +169 -0
  50. omnirank/connect/http.py +310 -0
  51. omnirank/connect/indexnow.py +373 -0
  52. omnirank/connect/naver.py +536 -0
  53. omnirank/connect/runner.py +515 -0
  54. omnirank/connect/runner_ga4_ai.py +59 -0
  55. omnirank/connect/runner_more.py +489 -0
  56. omnirank/connect/runner_regional.py +260 -0
  57. omnirank/connect/secrets.py +190 -0
  58. omnirank/connect/urlcheck.py +41 -0
  59. omnirank/connect/yandex.py +350 -0
  60. omnirank/crawl/__init__.py +11 -0
  61. omnirank/crawl/analyze.py +493 -0
  62. omnirank/crawl/crawler.py +491 -0
  63. omnirank/crawl/custom.py +175 -0
  64. omnirank/crawl/export.py +67 -0
  65. omnirank/crawl/fetcher.py +212 -0
  66. omnirank/crawl/parse.py +102 -0
  67. omnirank/crawl/render.py +148 -0
  68. omnirank/crawl/robotsgate.py +198 -0
  69. omnirank/crawl/runner.py +295 -0
  70. omnirank/crawl/sitemap.py +99 -0
  71. omnirank/crawl/text.py +20 -0
  72. omnirank/crawl/urls.py +100 -0
  73. omnirank/crawlers.py +564 -0
  74. omnirank/data/ai_crawlers.json +269 -0
  75. omnirank/data/ai_referrers.json +42 -0
  76. omnirank/fetch.py +107 -0
  77. omnirank/fixes/__init__.py +92 -0
  78. omnirank/fixes/base.py +232 -0
  79. omnirank/fixes/canonical.py +243 -0
  80. omnirank/fixes/schema.py +126 -0
  81. omnirank/formats.py +134 -0
  82. omnirank/framework.py +223 -0
  83. omnirank/gates/__init__.py +48 -0
  84. omnirank/gates/aeo.py +114 -0
  85. omnirank/gates/contradictions.py +280 -0
  86. omnirank/gates/crawler_policy.py +85 -0
  87. omnirank/gates/geo.py +152 -0
  88. omnirank/gates/hygiene.py +81 -0
  89. omnirank/gates/jsonld.py +282 -0
  90. omnirank/gates/onpage.py +177 -0
  91. omnirank/gates/perf.py +115 -0
  92. omnirank/gates/security.py +264 -0
  93. omnirank/gates/seo.py +118 -0
  94. omnirank/gates/site.py +248 -0
  95. omnirank/geo_artifacts.py +199 -0
  96. omnirank/html.py +79 -0
  97. omnirank/keywords/__init__.py +5 -0
  98. omnirank/keywords/constants.py +69 -0
  99. omnirank/keywords/engine.py +384 -0
  100. omnirank/keywords/report.py +143 -0
  101. omnirank/keywords/runner.py +160 -0
  102. omnirank/keywords/source.py +60 -0
  103. omnirank/keywords/text.py +45 -0
  104. omnirank/locator.py +480 -0
  105. omnirank/logs/__init__.py +0 -0
  106. omnirank/logs/analyze.py +127 -0
  107. omnirank/logs/bots.py +69 -0
  108. omnirank/logs/ipranges.py +191 -0
  109. omnirank/logs/parse.py +452 -0
  110. omnirank/logs/paths.py +22 -0
  111. omnirank/logs/privacy.py +105 -0
  112. omnirank/logs/runner.py +179 -0
  113. omnirank/mcp_server.py +1480 -0
  114. omnirank/netguard.py +525 -0
  115. omnirank/packs/__init__.py +6 -0
  116. omnirank/packs/backlinks.py +535 -0
  117. omnirank/packs/blog.py +544 -0
  118. omnirank/packs/blog_cross.py +468 -0
  119. omnirank/packs/crawlers.py +23 -0
  120. omnirank/packs/entity.py +492 -0
  121. omnirank/packs/feeds.py +150 -0
  122. omnirank/packs/frontmatter.py +59 -0
  123. omnirank/packs/gsc.py +421 -0
  124. omnirank/packs/local.py +879 -0
  125. omnirank/packs/mdscan.py +326 -0
  126. omnirank/packs/miniyaml.py +378 -0
  127. omnirank/packs/model.py +46 -0
  128. omnirank/packs/product.py +979 -0
  129. omnirank/packs/refresh.py +165 -0
  130. omnirank/packs/runner.py +277 -0
  131. omnirank/packs/sitescan.py +294 -0
  132. omnirank/packs/textsafe.py +79 -0
  133. omnirank/packs/xmlsafe.py +92 -0
  134. omnirank/page.py +42 -0
  135. omnirank/registry.py +302 -0
  136. omnirank/report.py +251 -0
  137. omnirank/report_cmd/__init__.py +7 -0
  138. omnirank/report_cmd/delta.py +58 -0
  139. omnirank/report_cmd/files.py +64 -0
  140. omnirank/report_cmd/model.py +208 -0
  141. omnirank/report_cmd/notify.py +195 -0
  142. omnirank/report_cmd/pdf.py +83 -0
  143. omnirank/report_cmd/portfolio.py +342 -0
  144. omnirank/report_cmd/render.py +379 -0
  145. omnirank/report_cmd/runner.py +267 -0
  146. omnirank/robots.py +172 -0
  147. omnirank/scanner/__init__.py +10 -0
  148. omnirank/scanner/badge.py +90 -0
  149. omnirank/scanner/cache.py +69 -0
  150. omnirank/scanner/cli.py +96 -0
  151. omnirank/scanner/engine.py +289 -0
  152. omnirank/scanner/limits.py +98 -0
  153. omnirank/scanner/server.py +143 -0
  154. omnirank/scanner/service.py +328 -0
  155. omnirank/schema/__init__.py +13 -0
  156. omnirank/schema/catalog.py +679 -0
  157. omnirank/schema/catalog_specs.py +350 -0
  158. omnirank/schema/core.py +306 -0
  159. omnirank/schema/extract.py +396 -0
  160. omnirank/schema/gate.py +121 -0
  161. omnirank/schema/runner.py +213 -0
  162. omnirank/schema/validate.py +504 -0
  163. omnirank/schema/vocab.py +305 -0
  164. omnirank/schemas/omnirank.config.schema.json +268 -0
  165. omnirank/track/__init__.py +0 -0
  166. omnirank/track/ai_prompts.py +207 -0
  167. omnirank/track/analysis.py +197 -0
  168. omnirank/track/constants.py +155 -0
  169. omnirank/track/cost.py +229 -0
  170. omnirank/track/discover.py +277 -0
  171. omnirank/track/discover_cli.py +309 -0
  172. omnirank/track/discover_constants.py +95 -0
  173. omnirank/track/engines.py +216 -0
  174. omnirank/track/estimate_view.py +212 -0
  175. omnirank/track/history.py +261 -0
  176. omnirank/track/runner.py +586 -0
  177. omnirank/track/stats.py +138 -0
  178. omnirank/track/storage.py +128 -0
  179. omnirank-0.5.0.dist-info/METADATA +47 -0
  180. omnirank-0.5.0.dist-info/RECORD +183 -0
  181. omnirank-0.5.0.dist-info/WHEEL +5 -0
  182. omnirank-0.5.0.dist-info/entry_points.txt +2 -0
  183. omnirank-0.5.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,213 @@
1
+ """Implementation of ``omnirank schema generate`` and ``omnirank schema validate``.
2
+
3
+ Exit codes: 0 ok; 1 required gaps remain / markup invalid;
4
+ 2 usage error or a page that could not be fetched. Nothing here writes a file.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from ..config import ConfigError, load_config
13
+ from ..fetch import fetch, make_client
14
+ from .catalog import (
15
+ CATALOG_TYPES,
16
+ all_types,
17
+ generate_from_sources,
18
+ listing,
19
+ )
20
+ from .core import dump_jsonld, generate
21
+ from .extract import facts_from_config, facts_from_frontmatter, facts_from_html, merge_facts
22
+ from .validate import ELIGIBILITY_CHECKED_ON, extract_jsonld, validate
23
+
24
+ MARKDOWN_SUFFIXES = {".md", ".markdown", ".mdx"}
25
+
26
+
27
+ def _err(message: str) -> None:
28
+ print(f"omnirank: {message}", file=sys.stderr)
29
+
30
+
31
+ def _is_url(text: str) -> bool:
32
+ return text.startswith(("http://", "https://"))
33
+
34
+
35
+ def _fetch_failure(url: str, got) -> str:
36
+ if got.is_redirect:
37
+ return (f"{url} redirects (status {got.status}); redirects are not followed, "
38
+ "pass the final URL")
39
+ if got.status == 0:
40
+ return f"could not fetch {url}: request failed ({got.text})"
41
+ return f"could not fetch {url} (status {got.status})"
42
+
43
+
44
+ def run_generate(args) -> int:
45
+ type_ = args.type
46
+ if type_ not in all_types():
47
+ _err(f"unknown schema type {type_!r}. Supported: {', '.join(sorted(all_types()))}")
48
+ return 2
49
+ data = None
50
+ if getattr(args, "data", None):
51
+ try:
52
+ data = json.loads(Path(args.data).read_text(encoding="utf-8"))
53
+ except (OSError, UnicodeDecodeError, json.JSONDecodeError, RecursionError) as exc:
54
+ _err(f"cannot read --data {args.data}: {exc}")
55
+ return 2
56
+ if not isinstance(data, dict):
57
+ _err("--data must be a JSON object")
58
+ return 2
59
+ if type_ not in CATALOG_TYPES:
60
+ _err(f"--data is only used by catalog types, not {type_}")
61
+ return 2
62
+
63
+ layers = []
64
+ try:
65
+ if args.config:
66
+ layers.append(facts_from_config(load_config(args.config)))
67
+ except ConfigError as exc:
68
+ _err(str(exc))
69
+ return 2
70
+
71
+ page_layers = []
72
+ html_text = md_text = None
73
+ if args.file:
74
+ path = Path(args.file)
75
+ if not path.is_file():
76
+ _err(f"file not found: {path}")
77
+ return 2
78
+ try:
79
+ text = path.read_text(encoding="utf-8")
80
+ except (OSError, UnicodeDecodeError) as exc:
81
+ _err(f"cannot read {path}: {exc}")
82
+ return 2
83
+ if path.suffix.lower() in MARKDOWN_SUFFIXES:
84
+ page_layers.append(facts_from_frontmatter(text))
85
+ md_text = text
86
+ else:
87
+ page_layers.append(facts_from_html(text, None))
88
+ html_text = text
89
+ elif args.page:
90
+ if not _is_url(args.page):
91
+ _err(f"--page needs an absolute http(s) URL, got {args.page!r}")
92
+ return 2
93
+ with make_client() as client:
94
+ got = fetch(client, args.page)
95
+ if not got.ok:
96
+ _err(_fetch_failure(args.page, got))
97
+ return 2
98
+ page_layers.append(facts_from_html(got.text, args.page))
99
+ html_text = got.text
100
+
101
+ # Frontmatter and page data describe the page; config describes the site. The first
102
+ # layer wins, so page facts beat config where the two overlap.
103
+ facts = merge_facts(*page_layers, *layers)
104
+ if type_ in CATALOG_TYPES:
105
+ result = generate_from_sources(
106
+ type_, html=html_text, frontmatter=md_text, data=data,
107
+ page_url=args.page if args.page else None,
108
+ config_facts=merge_facts(*layers))
109
+ else:
110
+ result = generate(type_, facts)
111
+ if args.json:
112
+ print(json.dumps(result.to_dict(), indent=2, ensure_ascii=False))
113
+ else:
114
+ print(dump_jsonld(result.jsonld))
115
+ print()
116
+ for note in result.notes:
117
+ print(f"Note: {note}")
118
+ if result.notes:
119
+ print()
120
+ required = result.required_gaps
121
+ if not result.omitted:
122
+ print("Gaps: none")
123
+ else:
124
+ print(f"Gaps ({len(result.omitted)} omitted, {len(required)} required). "
125
+ "Nothing was invented; each property below was left out.")
126
+ for gap in result.omitted:
127
+ tag = "required" if gap.required else "optional"
128
+ print(f" [{tag}] {gap.property}: {gap.reason}")
129
+ return 1 if result.required_gaps else 0
130
+
131
+
132
+ def run_list(args) -> int:
133
+ rows = listing()
134
+ if args.json:
135
+ print(json.dumps(rows, indent=2, ensure_ascii=False))
136
+ return 0
137
+ width = max(len(r["type"]) for r in rows)
138
+ print(f"{len(rows)} schema.org types (evidence tag: validity of the vocabulary; "
139
+ "eligibility follows Google's docs and can go stale)")
140
+ for r in rows:
141
+ print(f" {r['type']:<{width}} {r['evidence']:<14} eligibility: {r['eligibility']}"
142
+ + (f" [{r['via']}]" if r["via"] != "core" and r["via"] != "catalog" else ""))
143
+ return 0
144
+
145
+
146
+ def _report_text(target: str, blocks: int, errors: list[str], reports: list) -> str:
147
+ lines = [f"Validated {blocks} JSON-LD block(s) from {target}"]
148
+ invalid = [(i, e) for i, r in enumerate(reports) for e in r.invalid]
149
+ if errors or invalid:
150
+ lines.append(f"INVALID ({len(errors) + len(invalid)})")
151
+ lines += [f" [parse] {e}" for e in errors]
152
+ lines += [f" [{e.code}] {e.path}: {e.message}" for _, e in invalid]
153
+ else:
154
+ lines.append("VALID: no structural or vocabulary errors found")
155
+ thin = [e for r in reports for e in r.not_eligible]
156
+ if thin:
157
+ lines.append(f"NOT ELIGIBLE ({len(thin)}): valid markup that lacks properties Google's "
158
+ f"documentation requires or recommends (tables dated {ELIGIBILITY_CHECKED_ON})")
159
+ lines += [f" [{e.level}] {e.path}: {e.message}" for e in thin]
160
+ loose = [e for r in reports for e in r.unrecognised]
161
+ if loose:
162
+ lines.append(f"UNRECOGNISED ({len(loose)}): not errors; outside OmniRank's bundled subset")
163
+ lines += [f" [{e.code}] {e.path}: {e.message}" for e in loose]
164
+ notes = sorted({n for r in reports for n in r.notes})
165
+ if len(reports) > 1:
166
+ notes.append(f"{len(reports)} JSON-LD scripts found; OmniRank emits one per page")
167
+ if notes:
168
+ lines.append("Notes")
169
+ lines += [f" {n}" for n in notes]
170
+ return "\n".join(lines)
171
+
172
+
173
+ def run_validate(args) -> int:
174
+ target = args.target
175
+ errors: list[str] = []
176
+ if _is_url(target):
177
+ with make_client() as client:
178
+ got = fetch(client, target)
179
+ if not got.ok:
180
+ _err(_fetch_failure(target, got))
181
+ return 2
182
+ extracted = extract_jsonld(got.text)
183
+ blocks, errors = extracted.blocks, extracted.errors
184
+ else:
185
+ path = Path(target)
186
+ if not path.is_file():
187
+ _err(f"file not found: {target}")
188
+ return 2
189
+ try:
190
+ text = path.read_text(encoding="utf-8")
191
+ except (OSError, UnicodeDecodeError) as exc:
192
+ _err(f"cannot read {target}: {exc}")
193
+ return 2
194
+ if path.suffix.lower() in {".json", ".jsonld"}:
195
+ try:
196
+ blocks = [json.loads(text)]
197
+ except (json.JSONDecodeError, RecursionError) as exc:
198
+ blocks, errors = [], [f"{target} is not valid JSON: {exc}"]
199
+ else:
200
+ extracted = extract_jsonld(text)
201
+ blocks, errors = extracted.blocks, extracted.errors
202
+
203
+ reports = [validate(b) for b in blocks]
204
+ if not blocks and not errors:
205
+ errors = ["no <script type=\"application/ld+json\"> found"]
206
+ ok = not errors and all(r.is_valid for r in reports)
207
+ if args.json:
208
+ print(json.dumps({"valid": ok, "parseErrors": errors,
209
+ "reports": [r.to_dict() for r in reports]},
210
+ indent=2, ensure_ascii=False))
211
+ else:
212
+ print(_report_text(target, len(blocks), errors, reports))
213
+ return 0 if ok else 1