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 Stadtundland(Provider): @property def domain(self) -> str: return "stadtundland.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: r.step("cookies.check") cookie_accept_btn = page.get_by_text("Alle akzeptieren") if await cookie_accept_btn.is_visible(): await cookie_accept_btn.click() r.step("cookies.accepted") else: r.step("cookies.absent") r.step("page.offline_check") if await page.get_by_role("heading", name="Hier ist etwas schief gelaufen").is_visible(): return ApplicationResult(False, message=_("ad_offline")) r.step("form.fill") await page.locator("#name").fill(p.firstname) await page.locator("#surname").fill(p.lastname) await page.locator("#street").fill(p.street) await page.locator("#houseNo").fill(p.house_number) await page.locator("#postalCode").fill(p.postcode) await page.locator("#city").fill(p.city) await page.locator("#phone").fill(p.telephone) await page.locator("#email").fill(p.email) await page.locator("#privacy").check() await page.locator("#provision").check() if not ctx.submit_forms: r.step("submit.dry_run") return ApplicationResult(True, _("application_success_dry")) r.step("submit.review"); await page.get_by_role("button", name="Eingaben prüfen").click() r.step("submit.send"); await page.get_by_role("button", name="Absenden").click() await page.wait_for_timeout(2000) r.step("success.check") if await page.locator("p").filter(has_text="Vielen Dank!").is_visible(): return ApplicationResult(True) r.step("success.not_found", "warn") return ApplicationResult(success=False, message=_("submit_conformation_msg_not_found"))