Datasets:
Download scripts/check_links.py from ulamai/UnsolvedEarth: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/datasets/ulamai/UnsolvedEarth/resolve/main/scripts/check_links.py
- Command line
-
hf download hf://datasets/ulamai/UnsolvedEarth/scripts/check_links.py
-
curl -L -o check_links.py https://huggingface.co/datasets/ulamai/UnsolvedEarth/resolve/main/scripts/check_links.py
1.63 kB
| #!/usr/bin/env python3 | |
| """ | |
| URL and citation link checker for UnsolvedEarth v1.0.0. | |
| Verifies that all source_url and literature_sources URLs use valid HTTPS schemes | |
| and clean URI formatting. | |
| """ | |
| import json | |
| import sys | |
| import urllib.parse | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| def is_valid_https_url(u): | |
| if not u or not isinstance(u, str): | |
| return False | |
| parsed = urllib.parse.urlparse(u) | |
| return parsed.scheme == "https" and bool(parsed.netloc) and " " not in u | |
| def main(): | |
| problems = json.loads((ROOT / "problems.json").read_text(encoding="utf-8")) | |
| sources = json.loads((ROOT / "source_registry.json").read_text(encoding="utf-8")) | |
| errors = [] | |
| checked = 0 | |
| for s in sources: | |
| u = s.get("url") | |
| checked += 1 | |
| if not is_valid_https_url(u): | |
| errors.append(f"{s.get('source_id')}: Invalid URL '{u}'") | |
| for p in problems: | |
| u = p.get("source_url") | |
| checked += 1 | |
| if not is_valid_https_url(u): | |
| errors.append(f"{p.get('id')}: Invalid source_url '{u}'") | |
| for ls in p.get("literature_sources") or []: | |
| lu = ls.get("url") | |
| checked += 1 | |
| if not is_valid_https_url(lu): | |
| errors.append(f"{p.get('id')}: Invalid literature_source URL '{lu}'") | |
| print(f"Checked {checked} URLs across sources and problems.") | |
| if errors: | |
| print(f"FAILED with {len(errors)} link errors:") | |
| for e in errors[:20]: | |
| print(" ", e) | |
| sys.exit(1) | |
| print("LINK CHECK PASSED: 0 errors.") | |
| if __name__ == "__main__": | |
| main() | |