fix: preserve Apec listing metadata

This commit is contained in:
Antoine 2026-06-01 13:30:33 +02:00
parent 00f3717995
commit 95b17a7c50
2 changed files with 20 additions and 7 deletions

View File

@ -3,7 +3,14 @@ from bs4 import BeautifulSoup
from job_research.models import ApecListing 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") soup = BeautifulSoup(html, "html.parser")
title = soup.find("h1") title = soup.find("h1")
@ -14,11 +21,13 @@ def normalize_apec_listing(url: str, html: str, fetched_at: str) -> ApecListing:
return ApecListing( return ApecListing(
source="apec", source="apec",
source_job_id=source_job_id,
url=url, url=url,
title=title.get_text(strip=True) if title else None, title=title.get_text(" ", strip=True) if title else None,
company=company.get_text(strip=True) if company else None, company=company.get_text(" ", strip=True) if company else None,
location=location.get_text(strip=True) if location else None, location=location.get_text(" ", strip=True) if location else None,
contract_type=contract.get_text(strip=True) if contract else None, contract_type=contract.get_text(" ", strip=True) if contract else None,
description_text=description.get_text(" ", strip=True) if description else None, description_text=description.get_text(" ", strip=True) if description else None,
published_at=published_at,
fetched_at=fetched_at, fetched_at=fetched_at,
) )

View File

@ -5,8 +5,8 @@ def test_normalize_apec_listing_extracts_minimal_shape() -> None:
html = """ html = """
<html> <html>
<body> <body>
<h1>Data Engineer</h1> <h1><span>Data</span> <strong>Engineer</strong></h1>
<div class="company">Example Corp</div> <div class="company"><span>Example</span> <em>Corp</em></div>
<div class="location">Paris</div> <div class="location">Paris</div>
<div class="contract">CDI</div> <div class="contract">CDI</div>
<div class="description">Build pipelines</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", url="https://example.test/job/123",
html=html, html=html,
fetched_at="2026-06-01T10:00:00Z", fetched_at="2026-06-01T10:00:00Z",
source_job_id="job-123",
published_at="2026-05-31",
) )
assert listing.source == "apec" assert listing.source == "apec"
assert listing.source_job_id == "job-123"
assert listing.url == "https://example.test/job/123" assert listing.url == "https://example.test/job/123"
assert listing.title == "Data Engineer" assert listing.title == "Data Engineer"
assert listing.company == "Example Corp" assert listing.company == "Example Corp"
assert listing.location == "Paris" assert listing.location == "Paris"
assert listing.contract_type == "CDI" assert listing.contract_type == "CDI"
assert listing.description_text == "Build pipelines" assert listing.description_text == "Build pipelines"
assert listing.published_at == "2026-05-31"
assert listing.fetched_at == "2026-06-01T10:00:00Z" assert listing.fetched_at == "2026-06-01T10:00:00Z"