fix: ruff formatting
This commit is contained in:
@@ -272,7 +272,9 @@ def funda_search_results(
|
|||||||
"""
|
"""
|
||||||
postgres.execute_many(insert_sql, rows)
|
postgres.execute_many(insert_sql, rows)
|
||||||
|
|
||||||
context.log.info(f"Inserted {len(rows)} search results into {_SCHEMA}.search_results")
|
context.log.info(
|
||||||
|
f"Inserted {len(rows)} search results into {_SCHEMA}.search_results"
|
||||||
|
)
|
||||||
|
|
||||||
return MaterializeResult(
|
return MaterializeResult(
|
||||||
metadata={
|
metadata={
|
||||||
@@ -307,7 +309,9 @@ def funda_listing_details(
|
|||||||
|
|
||||||
# Read listing IDs from search results
|
# Read listing IDs from search results
|
||||||
with engine.connect() as conn:
|
with engine.connect() as conn:
|
||||||
result = conn.execute(text(f"SELECT DISTINCT global_id FROM {_SCHEMA}.search_results"))
|
result = conn.execute(
|
||||||
|
text(f"SELECT DISTINCT global_id FROM {_SCHEMA}.search_results")
|
||||||
|
)
|
||||||
ids = [row[0] for row in result if row[0]]
|
ids = [row[0] for row in result if row[0]]
|
||||||
|
|
||||||
if not ids:
|
if not ids:
|
||||||
@@ -436,11 +440,15 @@ def funda_price_history(
|
|||||||
|
|
||||||
# Read listings from details table
|
# Read listings from details table
|
||||||
with engine.connect() as conn:
|
with engine.connect() as conn:
|
||||||
result = conn.execute(text(f"SELECT DISTINCT global_id FROM {_SCHEMA}.listing_details"))
|
result = conn.execute(
|
||||||
|
text(f"SELECT DISTINCT global_id FROM {_SCHEMA}.listing_details")
|
||||||
|
)
|
||||||
ids = [row[0] for row in result if row[0]]
|
ids = [row[0] for row in result if row[0]]
|
||||||
|
|
||||||
if not ids:
|
if not ids:
|
||||||
context.log.warning("No listing details found – run funda_listing_details first.")
|
context.log.warning(
|
||||||
|
"No listing details found – run funda_listing_details first."
|
||||||
|
)
|
||||||
return MaterializeResult(metadata={"count": 0})
|
return MaterializeResult(metadata={"count": 0})
|
||||||
|
|
||||||
context.log.info(f"Fetching price history for {len(ids)} listings …")
|
context.log.info(f"Fetching price history for {len(ids)} listings …")
|
||||||
@@ -505,7 +513,10 @@ def funda_price_history(
|
|||||||
|
|
||||||
def _search_preview_table(rows: list[dict]) -> str:
|
def _search_preview_table(rows: list[dict]) -> str:
|
||||||
"""Build a markdown table for search result metadata preview."""
|
"""Build a markdown table for search result metadata preview."""
|
||||||
lines = ["| Title | City | Price | Area | Bedrooms |", "| --- | --- | --- | --- | --- |"]
|
lines = [
|
||||||
|
"| Title | City | Price | Area | Bedrooms |",
|
||||||
|
"| --- | --- | --- | --- | --- |",
|
||||||
|
]
|
||||||
for r in rows:
|
for r in rows:
|
||||||
price = f"€{r['price']:,}" if r.get("price") else "–"
|
price = f"€{r['price']:,}" if r.get("price") else "–"
|
||||||
area = f"{r['living_area']} m²" if r.get("living_area") else "–"
|
area = f"{r['living_area']} m²" if r.get("living_area") else "–"
|
||||||
|
|||||||
@@ -111,7 +111,11 @@ class TestFundaSearchResults:
|
|||||||
"postgres": MockPostgresResource(engine, rows),
|
"postgres": MockPostgresResource(engine, rows),
|
||||||
},
|
},
|
||||||
run_config={
|
run_config={
|
||||||
"ops": {"funda_search_results": {"config": {"max_pages": 1, **(config or {})}}}
|
"ops": {
|
||||||
|
"funda_search_results": {
|
||||||
|
"config": {"max_pages": 1, **(config or {})}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
@@ -188,7 +192,10 @@ class TestFundaSearchResults:
|
|||||||
client = MagicMock()
|
client = MagicMock()
|
||||||
client.search_listing.return_value = []
|
client.search_listing.return_value = []
|
||||||
self._run(client, config={"object_type": "house, apartment"})
|
self._run(client, config={"object_type": "house, apartment"})
|
||||||
assert client.search_listing.call_args[1]["object_type"] == ["house", "apartment"]
|
assert client.search_listing.call_args[1]["object_type"] == [
|
||||||
|
"house",
|
||||||
|
"apartment",
|
||||||
|
]
|
||||||
|
|
||||||
def test_energy_label_split_by_comma(self):
|
def test_energy_label_split_by_comma(self):
|
||||||
client = MagicMock()
|
client = MagicMock()
|
||||||
|
|||||||
@@ -114,7 +114,9 @@ class TestSearchPreviewTable:
|
|||||||
assert "–" in result
|
assert "–" in result
|
||||||
|
|
||||||
def test_multiple_rows_correct_count(self):
|
def test_multiple_rows_correct_count(self):
|
||||||
rows = [{"title": f"St {i}", "city": "City", "price": i * 1000} for i in range(5)]
|
rows = [
|
||||||
|
{"title": f"St {i}", "city": "City", "price": i * 1000} for i in range(5)
|
||||||
|
]
|
||||||
result = _search_preview_table(rows)
|
result = _search_preview_table(rows)
|
||||||
lines = result.split("\n")
|
lines = result.split("\n")
|
||||||
# header + separator + 5 data rows
|
# header + separator + 5 data rows
|
||||||
|
|||||||
Reference in New Issue
Block a user