diff --git a/handlers/gewobag_handler.py b/handlers/gewobag_handler.py index c37e678..44c2d15 100644 --- a/handlers/gewobag_handler.py +++ b/handlers/gewobag_handler.py @@ -28,12 +28,13 @@ class GewobagHandler(BaseHandler): status == 404 or (page_title and "404" in page_title) or (page_title and "nicht gefunden" in page_title.lower()) or - ("Mietangebot nicht gefunden" in page_content) + ("Mietangebot nicht gefunden" in page_content) or + ("Bewerbungsphase abgeschlossen" in page_content) ) if is_404: - logger.warning(f"[GEWOBAG] Listing is down (404 or unavailable): {listing['link']}") + logger.warning(f"[GEWOBAG] Listing is down (404, unavailable, or application phase closed): {listing['link']}") result["success"] = False - result["message"] = "Listing is no longer available (404). Application impossible. Will not retry." + result["message"] = "Listing no longer available or application phase closed" result["deactivated"] = True return result @@ -205,18 +206,27 @@ class GewobagHandler(BaseHandler): if for_myself_option: await for_myself_option.click() logger.info("[GEWOBAG] Selected 'für mich selbst'") + await asyncio.sleep(1) # Wait for conditional fields to appear form_filled = True except Exception as e: logger.warning(f"[GEWOBAG] Could not select 'für wen' dropdown: {e}") - # Mobilfunknummer (Mobile phone) - REQUIRED + # Mobilfunknummer (Mobile phone) - REQUIRED (appears after dropdown selection) try: mobile_phone = os.environ.get("FORM_PHONE", "") - mobile_input = await iframe_page.query_selector('#formly_17_input_$$_telephone_number_$$_0') - if mobile_input: - await mobile_input.fill(mobile_phone) - logger.info(f"[GEWOBAG] Filled Mobilfunknummer: {mobile_phone}") - form_filled = True + if mobile_phone: + # Wait for the field to appear + await iframe_page.wait_for_selector('#formly_17_input_$$_telephone_number_$$_0', timeout=5000, state='visible') + mobile_input = await iframe_page.query_selector('#formly_17_input_$$_telephone_number_$$_0') + if mobile_input: + await mobile_input.scroll_into_view_if_needed() + await mobile_input.fill(mobile_phone) + logger.info(f"[GEWOBAG] Filled Mobilfunknummer: {mobile_phone}") + form_filled = True + else: + logger.warning("[GEWOBAG] Mobilfunknummer field not found") + else: + logger.warning("[GEWOBAG] FORM_PHONE environment variable is empty") except Exception as e: logger.warning(f"[GEWOBAG] Could not fill Mobilfunknummer: {e}")