refactor: one rescrape command for both freshness

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 16:43:57 +01:00
1 parent 3b16ee2633
commit 35ad46e8c5
7 files changed
+104 -58

No files matched your search

+8 -4
View File
@@ -4,15 +4,16 @@ from __future__ import annotations
import shutil
import subprocess
import sys
from collections.abc import Mapping
from pathlib import Path
from core.paths import REPO_ROOT
from freshness.scrapers import rescrape_command
def scrape_into_copy(
module: str, source: Path, workdir: Path, timeout: int = 900,
extra: tuple[str, ...] = (),
area: str, name: str, source: Path, workdir: Path,
registry: Mapping[str, Mapping] | None = None, timeout: int = 900,
) -> tuple[Path, str | None]:
"""Run a scraper's own write path on a throwaway copy of *source*.
@@ -20,9 +21,12 @@ def scrape_into_copy(
the scraper preserves and the diff shows only what the scrape changes.
"""
target = workdir / source.name
command = rescrape_command(area, name, target, registry)
if command is None:
raise ValueError(f"no scraper rewrites {area} {name}")
shutil.copyfile(source, target)
proc = subprocess.run(
[sys.executable, "-m", module, "-o", str(target), *extra],
command,
cwd=REPO_ROOT,
capture_output=True,
text=True,