upd gewobag

This commit is contained in:
Aron Petau 2026-01-08 21:04:43 +01:00
parent afb87d7d3c
commit 92912e8487
4 changed files with 300 additions and 5 deletions

View file

@ -236,10 +236,83 @@ class GewobagHandler(BaseHandler):
if wbs_ja:
await wbs_ja.click()
logger.info("[GEWOBAG] Selected WBS: Ja")
await asyncio.sleep(1) # Wait for conditional WBS fields to appear
# Save debug HTML after WBS fields are visible
try:
html_content = await iframe_page.content()
debug_html_path = DATA_DIR / f"gewobag_wbs_fields_{listing['id']}.html"
with open(debug_html_path, "w", encoding="utf-8") as f:
f.write(html_content)
logger.info(f"[GEWOBAG] Saved WBS fields debug HTML to {debug_html_path}")
except Exception as e:
logger.warning(f"[GEWOBAG] Could not save WBS debug HTML: {e}")
form_filled = True
except Exception as e:
logger.warning(f"[GEWOBAG] Could not select WBS: {e}")
# WBS Gültigkeit (validity date) - appears after selecting Ja
try:
wbs_valid_until = os.environ.get("FORM_WBS_VALID_UNTIL", "26.11.2026")
wbs_date_input = await iframe_page.query_selector('#formly_6_input_\\$\\$_wbs_valid_until_\\$\\$_0')
if wbs_date_input:
await wbs_date_input.fill(wbs_valid_until)
logger.info(f"[GEWOBAG] Filled WBS Gültigkeit: {wbs_valid_until}")
form_filled = True
except Exception as e:
logger.warning(f"[GEWOBAG] Could not fill WBS Gültigkeit: {e}")
# WBS Art/Bezeichnung (type) dropdown - appears after selecting Ja
try:
wbs_type = os.environ.get("FORM_WBS_TYPE", "WBS 100")
wbs_type_input = await iframe_page.query_selector('#formly_6_select_gewobag_art_bezeichnung_des_wbs_1')
if wbs_type_input:
await wbs_type_input.click()
await iframe_page.wait_for_timeout(300)
wbs_type_option = await iframe_page.query_selector(f'.ng-option:has-text("{wbs_type}")')
if wbs_type_option:
await wbs_type_option.click()
logger.info(f"[GEWOBAG] Selected WBS Type: {wbs_type}")
form_filled = True
except Exception as e:
logger.warning(f"[GEWOBAG] Could not select WBS Type: {e}")
# WBS Anzahl Räume (number of rooms) dropdown - appears after selecting Ja
try:
wbs_rooms = os.environ.get("FORM_WBS_ROOMS", "1")
wbs_rooms_input = await iframe_page.query_selector('#formly_7_select_\\$\\$_wbs_max_number_rooms_\\$\\$_0')
if wbs_rooms_input:
await wbs_rooms_input.click()
await iframe_page.wait_for_timeout(300)
wbs_rooms_option = await iframe_page.query_selector(f'.ng-option:has-text("{wbs_rooms}")')
if wbs_rooms_option:
await wbs_rooms_option.click()
logger.info(f"[GEWOBAG] Selected WBS Rooms: {wbs_rooms}")
form_filled = True
except Exception as e:
logger.warning(f"[GEWOBAG] Could not select WBS Rooms: {e}")
# WBS file upload - Upload the WBS PDF and PNG from data/uploads
try:
wbs_files = [
Path("data/uploads/WBS_Antrag_Bestaetigung.pdf"),
Path("data/uploads/WBS_Rechner.png")
]
existing_files = [str(f) for f in wbs_files if f.exists()]
if existing_files:
file_input = await iframe_page.query_selector('input[type="file"]')
if file_input:
await file_input.set_input_files(existing_files)
await asyncio.sleep(1) # Wait for upload to process
logger.info(f"[GEWOBAG] Uploaded {len(existing_files)} WBS file(s): {', '.join([Path(f).name for f in existing_files])}")
form_filled = True
else:
logger.warning("[GEWOBAG] No WBS files found in data/uploads")
except Exception as e:
logger.warning(f"[GEWOBAG] Could not upload WBS files: {e}")
# Privacy checkbox (Main Datenschutzbestimmungen) - REQUIRED
try:
privacy_checkbox = await iframe_page.query_selector('#formly_20_checkbox_gewobag_datenschutzhinweis_bestaetigt_0')

View file

@ -177,14 +177,21 @@ class WGCompanyNotifier:
content = await page.content()
# Extract email (look for patterns like email: xxx@yyy.zz or Email: xxx)
# Priority: Look for email in table cell context (WG-specific email), exclude footer email
email_patterns = [
r'[Ee]-?[Mm]ail[:\s]+([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})',
r'([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})'
r'email\s*:\s*</font></b></td>\s*<td[^>]*>.*?mailto:([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})', # Table cell email
r'<a href="mailto:([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})">', # Any mailto link
r'[Ee]-?[Mm]ail[:\s]+([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})', # Plain email: pattern
]
for pattern in email_patterns:
email_match = re.search(pattern, content)
if email_match:
details["email"] = email_match.group(1)
email_matches = re.finditer(pattern, content, re.IGNORECASE | re.DOTALL)
for match in email_matches:
email = match.group(1)
# Exclude the footer/contact email
if email != "wgcompany@wgcompany.de":
details["email"] = email
break
if "email" in details:
break
# Extract WG name from URL