lazyflat/apply/providers/degewo.py
Moritz 7444f90d6a per-step screenshot + html snapshots, matches-only list, full German UI, CSV export
* apply: Recorder.step_snap(page, name) captures both a JPEG screenshot and
  the page HTML for every major moment; every provider now calls step_snap at
  each logical step so failure reports contain the exact DOM and rendered
  state at every stage of the flow
* ZIP report: each snapshot becomes snapshots/NN_<label>.jpg +
  snapshots/NN_<label>.html for AI-assisted debugging
* web: Wohnungsliste zeigt nur noch Flats, die die eigenen Filter treffen;
  Match-Chip entfernt (Liste ist jetzt implizit matchend)
* UI komplett auf Deutsch: Protokoll statt Logs, Administrator statt admin,
  Trockenmodus statt dry-run, Automatik pausiert statt circuit open,
  Alarm statt Alert, Abmelden statt Logout
* Wohnungen-Header: Zeile 1 Info (Alarm + Filter), Zeile 2 Schalter mit
  echten Radio-Paaren (An/Aus) für Automatisch bewerben und Trockenmodus;
  hx-confirm auf den kritischen Radios; per-form CSS für sichtbaren Check-State
* Protokoll: von/bis-Datumsfilter (Berliner Zeit) + CSV-Download
  (/logs/export.csv) mit UTC + lokaler Zeit

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

108 lines
5.7 KiB
Python

import logging
from actions import open_page
from classes.application_result import ApplicationResult
from language import _
from providers._provider import ApplyContext, Provider
logger = logging.getLogger("flat-apply")
class Degewo(Provider):
@property
def domain(self) -> str:
return "degewo.de"
async def apply_for_flat(self, url: str, ctx: ApplyContext) -> ApplicationResult:
r = ctx.recorder
p = ctx.profile
async with open_page(url, recorder=r) as page:
await r.step_snap(page, "cookies.check")
cookie_accept_btn = page.locator("#cookie-consent-submit-all")
if await cookie_accept_btn.is_visible():
await cookie_accept_btn.click()
await r.step_snap(page, "cookies.accepted")
await r.step_snap(page, "page.404_check")
if page.url == "https://www.degewo.de/immosuche/404":
await r.step_snap(page, "abort.not_found", status="warn")
return ApplicationResult(False, message=_("ad_offline"))
await r.step_snap(page, "ad.deactivated_check")
if await page.locator("span", has_text="Inserat deaktiviert").is_visible():
await r.step_snap(page, "abort.deactivated", status="warn")
return ApplicationResult(False, message=_("ad_deactivated"))
await r.step_snap(page, "page.moved_check")
if await page.locator("h1", has_text="Diese Seite ist umgezogen!").is_visible():
await r.step_snap(page, "abort.moved", status="warn")
return ApplicationResult(False, message=_("ad_offline"))
await r.step_snap(page, "form.open")
await page.get_by_role("link", name="Kontakt").click()
await r.step_snap(page, "iframe.locate")
form_frame = page.frame_locator("iframe[src*='wohnungshelden']")
await r.step_snap(page, "form.fill_personal")
await form_frame.locator("#salutation").fill(p.salutation)
await form_frame.get_by_role("option", name=p.salutation, exact=True).click()
await form_frame.locator("#firstName").fill(p.firstname)
await form_frame.locator("#lastName").fill(p.lastname)
await form_frame.locator("#email").fill(p.email)
await form_frame.locator("input[title='Telefonnummer']").fill(p.telephone)
await form_frame.locator("input[title='Anzahl einziehende Personen']").fill(str(p.person_count))
await page.wait_for_timeout(1000)
await r.step_snap(page, "form.wbs_section")
wbs_question = form_frame.locator("input[id*='wbs_available'][id$='Ja']")
if await wbs_question.is_visible():
if not p.is_possessing_wbs:
await r.step_snap(page, "wbs_required_abort", status="warn")
return ApplicationResult(False, _("wbs_required"))
await wbs_question.click()
await form_frame.locator("input[title='WBS gültig bis']").fill(p.wbs_valid_till_dt().strftime("%d.%m.%Y"))
await page.wait_for_timeout(1000)
wbs_rooms_select = form_frame.locator("ng-select[id*='wbs_max_number_rooms']")
await wbs_rooms_select.click()
await page.wait_for_timeout(1000)
await form_frame.get_by_role("option", name=str(p.wbs_rooms), exact=True).click()
await page.wait_for_timeout(1000)
await form_frame.locator("ng-select[id*='fuer_wen_ist_wohnungsanfrage']").click()
await page.wait_for_timeout(1000)
await form_frame.get_by_role("option", name="Für mich selbst").click()
await r.step_snap(page, "form.filled")
if not ctx.submit_forms:
await r.step_snap(page, "submit.dry_run")
return ApplicationResult(success=True, message=_("application_success_dry"))
await r.step_snap(page, "submit.click")
await form_frame.locator("button[data-cy*='btn-submit']").click()
await page.wait_for_timeout(3000)
await r.step_snap(page, "success.check")
if await page.locator("h4", has_text="Vielen Dank für das Übermitteln Ihrer Informationen. Sie können dieses Fenster jetzt schließen.").is_visible():
return ApplicationResult(success=True)
elif await self._missing_fields_warning(page):
await r.step_snap(page, "missing_fields_detected", status="warn")
return ApplicationResult(success=False, message=_("missing_fields"))
elif await self._already_applied_warning(page):
await r.step_snap(page, "already_applied_detected", status="warn")
return ApplicationResult(success=False, message=_("already_applied"))
await r.step_snap(page, "success.not_found", status="warn")
return ApplicationResult(success=False, message=_("submit_conformation_msg_not_found"))
async def _already_applied_warning(self, page) -> bool:
await page.wait_for_timeout(1000)
f = page.frame_locator("iframe[src*='wohnungshelden']")
msg = f.locator("span.ant-alert-message",
has_text="Es existiert bereits eine Anfrage mit dieser E-Mail Adresse")
return await msg.first.is_visible()
async def _missing_fields_warning(self, page) -> bool:
await page.wait_for_timeout(1000)
f = page.frame_locator("iframe[src*='wohnungshelden']")
msg = f.locator("span.ant-alert-message",
has_text="Es wurden nicht alle Felder korrekt befüllt. Bitte prüfen Sie ihre Eingaben")
return await msg.first.is_visible()