Files
ginnoir cb294f72a0 fix: address whole-branch review findings for update-swarm
- versions: require entire normalized string to be numeric so dates
  and hotfix suffixes compare as incomparable instead of eq/gt
- hosts: exact host or dot-suffix match rejects lookalikes like
  notmediafire.com and evilmega.nz; GitHub stays exact-set
- census: lazy extractor loop so a later OSError no longer discards an
  earlier sidecar changelog hit
- jobs: watchlist parses only table rows whose vault-note cell is a
  bare wikilink (skips parenthetical related/complete notes); wanted
  also matches bold names in Wanted.md tables with Pokemon prefix
  stripped and casefolded
- cli: validate-scouts and judge raise SystemExit when jobs.json has
  jobs but scouts/ has zero valid files
- fetch: download forwards timeout=60 to urlopen and writes to a
  .part file then os.replace, removing the partial on any failure
2026-08-14 15:11:16 -05:00

41 lines
1.4 KiB
Python

from __future__ import annotations
from urllib.parse import urlparse
GITHUB_HOSTS = frozenset(("github.com", "raw.githubusercontent.com", "objects.githubusercontent.com"))
# Exact host or dot-suffix match — `endswith(d)` alone accepts lookalikes like
# `notmediafire.com` or `evilmega.nz`.
SUFFIX_HOSTS = {
"archive.org": "archive",
"mediafire.com": "mediafire",
"mega.nz": "mega",
"mega.co.nz": "mega",
"itch.io": "itch",
"ko-fi.com": "kofi",
"hackdex.app": "hackdex",
"pokecommunity.com": "pokecommunity",
}
def _host_match(host: str, domain: str) -> bool:
return host == domain or host.endswith("." + domain)
def classify_url(url: str) -> tuple[str, str]:
p = urlparse(url or "")
host = (p.netloc or "").lower().removeprefix("www.")
path = p.path or ""
if host in GITHUB_HOSTS:
if host != "github.com" or "/releases/download/" in path:
return "github", "ungated"
return "github", "gated"
for domain, label in SUFFIX_HOSTS.items():
if _host_match(host, domain):
if label == "mega":
return "mega", "ungated" if p.fragment else "gated"
if label in ("archive", "mediafire"):
return label, "ungated"
return label, "gated"
if host in ("drive.google.com", "docs.google.com"):
return "drive", "gated"
if host in ("discord.com", "discord.gg"):
return "discord", "gated"
return "other", "gated"