File size: 969 Bytes
ddd1866
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations

import re
from pathlib import Path


def slugify_company_name(company_name: str) -> str:
    """Convert a company name into a filesystem-safe identifier."""
    normalized = re.sub(r"[^a-zA-Z0-9]+", "-", company_name.strip().lower())
    return normalized.strip("-") or "unknown-company"


def save_debug_html(company_name: str, html: str, stage: str, debug_dir: Path) -> Path | None:
    """Persist raw HTML so scraper failures can be inspected outside the app."""
    if not html:
        return None

    debug_dir.mkdir(parents=True, exist_ok=True)
    file_name = f"{slugify_company_name(company_name)}__{stage}.html"
    output_path = debug_dir / file_name
    output_path.write_text(html, encoding="utf-8")
    return output_path


def log_debug_header(company_name: str) -> None:
    print("=" * 60)
    print(f"COMPANY: {company_name}")


def log_debug_line(label: str, value: object) -> None:
    print(f"{label}: {value}")