lazyflat/web/matching.py
EiSiMo ebb11178e7 chore: sweep dead code across all three services
Per review §1 — verified no callers before each deletion:

- _next_scrape_utc (context dict key never read by any template)
- ALERT_SCRAPE_INTERVAL_SECONDS settings import (only _next_scrape_utc read it)
- alert/paths.py (imported by nothing)
- alert/settings.py LANGUAGE (alert doesn't use translations.toml)
- alert/main.py: the vestigial `c = {}` connectivity dict, the comment
  about re-enabling it, and the entire connectivity block in
  _flat_payload — the web-side columns stay NULL on insert now
- alert/maps.py: DESTINATIONS, calculate_score, _get_next_weekday,
  _calculate_transfers (only geocode is used in the scraper)
- alert/flat.py: connectivity + display_address properties,
  _connectivity field, unused datetime import
- apply/utils.py str_to_preview (no callers) — file removed
- web/matching.py: max_morning_commute + commute check
- web/app.py: don't pass connectivity dict into flat_matches_filter,
  don't write email_address through update_notifications
- web/db.py: get_error (no callers); drop kill_switch,
  max_morning_commute, email_address from their allowed-sets so they're
  not writable through update_* anymore
- web/settings.py + docker-compose.yml: SMTP_HOST/PORT/USERNAME/PASSWORD/
  FROM/STARTTLS (notifications.py is telegram-only now)

DB columns themselves (kill_switch, email_address, max_morning_commute,
connectivity_morning_time, connectivity_night_time) stay in the schema
— SQLite can't drop them cheaply and they're harmless.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 19:06:05 +02:00

49 lines
1.5 KiB
Python

"""
Per-user filter matching.
Each user has one row in user_filters. A flat matches the user if all
of the user's non-null constraints are satisfied. Empty filters = matches all.
"""
import logging
from typing import Iterable
logger = logging.getLogger("web.matching")
def flat_matches_filter(flat: dict, f: dict | None) -> bool:
"""f is a user_filters row converted to dict (or None = no filter set)."""
if not f:
return True
rooms = flat.get("rooms") or 0.0
rent = flat.get("total_rent") or 0.0
size = flat.get("size") or 0.0
wbs_str = str(flat.get("wbs", "")).strip().lower()
if f.get("rooms_min") is not None and rooms < float(f["rooms_min"]):
return False
if f.get("rooms_max") is not None and rooms > float(f["rooms_max"]):
return False
if f.get("max_rent") is not None and rent > float(f["max_rent"]):
return False
if f.get("min_size") is not None and size < float(f["min_size"]):
return False
wbs_req = (f.get("wbs_required") or "").strip().lower()
if wbs_req == "yes":
if not wbs_str or wbs_str in ("kein", "nein", "no", "ohne", "-"):
return False
elif wbs_req == "no":
if wbs_str and wbs_str not in ("kein", "nein", "no", "ohne", "-"):
return False
return True
def row_to_dict(row) -> dict:
if row is None:
return {}
try:
return {k: row[k] for k in row.keys()}
except Exception:
return dict(row)