fix: preserve Apec listing metadata
This commit is contained in:
parent
00f3717995
commit
95b17a7c50
@ -3,7 +3,14 @@ from bs4 import BeautifulSoup
|
||||
from job_research.models import ApecListing
|
||||
|
||||
|
||||
def normalize_apec_listing(url: str, html: str, fetched_at: str) -> ApecListing:
|
||||
def normalize_apec_listing(
|
||||
url: str,
|
||||
html: str,
|
||||
fetched_at: str,
|
||||
*,
|
||||
source_job_id: str | None = None,
|
||||
published_at: str | None = None,
|
||||
) -> ApecListing:
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
|
||||
title = soup.find("h1")
|
||||
@ -14,11 +21,13 @@ def normalize_apec_listing(url: str, html: str, fetched_at: str) -> ApecListing:
|
||||
|
||||
return ApecListing(
|
||||
source="apec",
|
||||
source_job_id=source_job_id,
|
||||
url=url,
|
||||
title=title.get_text(strip=True) if title else None,
|
||||
company=company.get_text(strip=True) if company else None,
|
||||
location=location.get_text(strip=True) if location else None,
|
||||
contract_type=contract.get_text(strip=True) if contract else None,
|
||||
title=title.get_text(" ", strip=True) if title else None,
|
||||
company=company.get_text(" ", strip=True) if company else None,
|
||||
location=location.get_text(" ", strip=True) if location else None,
|
||||
contract_type=contract.get_text(" ", strip=True) if contract else None,
|
||||
description_text=description.get_text(" ", strip=True) if description else None,
|
||||
published_at=published_at,
|
||||
fetched_at=fetched_at,
|
||||
)
|
||||
|
||||
@ -5,8 +5,8 @@ def test_normalize_apec_listing_extracts_minimal_shape() -> None:
|
||||
html = """
|
||||
<html>
|
||||
<body>
|
||||
<h1>Data Engineer</h1>
|
||||
<div class="company">Example Corp</div>
|
||||
<h1><span>Data</span> <strong>Engineer</strong></h1>
|
||||
<div class="company"><span>Example</span> <em>Corp</em></div>
|
||||
<div class="location">Paris</div>
|
||||
<div class="contract">CDI</div>
|
||||
<div class="description">Build pipelines</div>
|
||||
@ -18,13 +18,17 @@ def test_normalize_apec_listing_extracts_minimal_shape() -> None:
|
||||
url="https://example.test/job/123",
|
||||
html=html,
|
||||
fetched_at="2026-06-01T10:00:00Z",
|
||||
source_job_id="job-123",
|
||||
published_at="2026-05-31",
|
||||
)
|
||||
|
||||
assert listing.source == "apec"
|
||||
assert listing.source_job_id == "job-123"
|
||||
assert listing.url == "https://example.test/job/123"
|
||||
assert listing.title == "Data Engineer"
|
||||
assert listing.company == "Example Corp"
|
||||
assert listing.location == "Paris"
|
||||
assert listing.contract_type == "CDI"
|
||||
assert listing.description_text == "Build pipelines"
|
||||
assert listing.published_at == "2026-05-31"
|
||||
assert listing.fetched_at == "2026-06-01T10:00:00Z"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user