multi-user: users, per-user profiles/filters/notifications, tab UI, apply forensics
* DB: users + user_profiles/filters/notifications/preferences; applications gets user_id + forensics_json + profile_snapshot_json; new errors table with 14d retention; schema versioning via MIGRATIONS list * auth: password hashes in DB (argon2); env vars seed first admin; per-user sessions; CSRF bound to user id * apply: personal info/WBS moved out of env into the request body; providers take an ApplyContext with Profile + submit_forms; full Playwright recorder (step log, console, page errors, network, screenshots, final HTML) * web: five top-level tabs (Wohnungen/Bewerbungen/Logs/Fehler/Einstellungen); settings sub-tabs profil/filter/benachrichtigungen/account/benutzer; per-user matching, auto-apply and notifications (UI/Telegram/SMTP); red auto-apply switch on Wohnungen tab; forensics detail view for bewerbungen and fehler; retention background thread Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e663386a19
commit
c630b500ef
36 changed files with 2763 additions and 1113 deletions
|
|
@ -1,129 +1,101 @@
|
|||
from actions import *
|
||||
from language import _
|
||||
from classes.application_result import ApplicationResult
|
||||
from providers._provider import Provider
|
||||
from settings import *
|
||||
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) -> ApplicationResult:
|
||||
async with open_page(url) as page:
|
||||
logger.info("\tSTEP 1: accepting cookies")
|
||||
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.locator("#cookie-consent-submit-all")
|
||||
if await cookie_accept_btn.is_visible():
|
||||
await cookie_accept_btn.click()
|
||||
logger.debug("\t\tcookie accept button clicked")
|
||||
else:
|
||||
logger.debug("\t\tno cookie accept button found")
|
||||
r.step("cookies.accepted")
|
||||
|
||||
logger.info("\tSTEP 2: check if the page was not found")
|
||||
r.step("page.404_check")
|
||||
if page.url == "https://www.degewo.de/immosuche/404":
|
||||
logger.debug("\t\t'page not found' message found - returning")
|
||||
return ApplicationResult(
|
||||
success=False,
|
||||
message=_("ad_offline"))
|
||||
logger.debug("\t\t'page not found' message not found")
|
||||
return ApplicationResult(False, message=_("ad_offline"))
|
||||
|
||||
logger.info("\tSTEP 3: check if the ad is deactivated")
|
||||
r.step("ad.deactivated_check")
|
||||
if await page.locator("span", has_text="Inserat deaktiviert").is_visible():
|
||||
logger.debug("\t\t'ad deactivated' message found - returning")
|
||||
return ApplicationResult(
|
||||
success=False,
|
||||
message=_("ad_deactivated"))
|
||||
logger.debug("\t\t'ad deactivated' message not found")
|
||||
return ApplicationResult(False, message=_("ad_deactivated"))
|
||||
|
||||
logger.info("\tSTEP 4: check if the page moved")
|
||||
r.step("page.moved_check")
|
||||
if await page.locator("h1", has_text="Diese Seite ist umgezogen!").is_visible():
|
||||
logger.debug("\t\t'page moved' message found - returning")
|
||||
return ApplicationResult(
|
||||
success=False,
|
||||
message=_("ad_offline"))
|
||||
logger.debug("\t\t'page moved' message not found")
|
||||
return ApplicationResult(False, message=_("ad_offline"))
|
||||
|
||||
|
||||
logger.info("\tSTEP 5: go to the application form")
|
||||
await page.get_by_role("link", name="Kontakt").click()
|
||||
|
||||
logger.info("\tSTEP 6: find the form iframe")
|
||||
r.step("form.open"); await page.get_by_role("link", name="Kontakt").click()
|
||||
r.step("iframe.locate")
|
||||
form_frame = page.frame_locator("iframe[src*='wohnungshelden']")
|
||||
|
||||
logger.info("\tSTEP 7: fill the form")
|
||||
await form_frame.locator("#salutation").fill(SALUTATION)
|
||||
await form_frame.get_by_role("option", name=SALUTATION, exact=True).click()
|
||||
await form_frame.locator("#firstName").fill(FIRSTNAME)
|
||||
await form_frame.locator("#lastName").fill(LASTNAME)
|
||||
await form_frame.locator("#email").fill(EMAIL)
|
||||
await form_frame.locator("input[title='Telefonnummer']").fill(TELEPHONE)
|
||||
await form_frame.locator("input[title='Anzahl einziehende Personen']").fill(str(PERSON_COUNT))
|
||||
r.step("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)
|
||||
|
||||
r.step("form.wbs_section")
|
||||
wbs_question = form_frame.locator("input[id*='wbs_available'][id$='Ja']")
|
||||
if await wbs_question.is_visible():
|
||||
if not IS_POSSESSING_WBS:
|
||||
if not p.is_possessing_wbs:
|
||||
r.step("wbs_required_abort", "warn")
|
||||
return ApplicationResult(False, _("wbs_required"))
|
||||
await wbs_question.click()
|
||||
await form_frame.locator("input[title='WBS gültig bis']").fill(WBS_VALID_TILL.strftime("%d.%m.%Y"))
|
||||
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)
|
||||
correct_wbs_room_option = form_frame.get_by_role("option", name=str(WBS_ROOMS), exact=True)
|
||||
await correct_wbs_room_option.click()
|
||||
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()
|
||||
|
||||
logger.info("\tSTEP 8: submit the form")
|
||||
if not SUBMIT_FORMS:
|
||||
logger.debug(f"\t\tdry run - not submitting")
|
||||
if not ctx.submit_forms:
|
||||
r.step("submit.dry_run")
|
||||
return ApplicationResult(success=True, message=_("application_success_dry"))
|
||||
await form_frame.locator("button[data-cy*='btn-submit']").click()
|
||||
|
||||
r.step("submit.click"); await form_frame.locator("button[data-cy*='btn-submit']").click()
|
||||
await page.wait_for_timeout(3000)
|
||||
|
||||
logger.info("\tSTEP 9: check the success")
|
||||
r.step("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():
|
||||
logger.info(f"\t\tsuccess detected by heading")
|
||||
return ApplicationResult(success=True)
|
||||
elif await self.is_missing_fields_warning(page):
|
||||
logger.warning(f"\t\tmissing fields warning detected")
|
||||
elif await self._missing_fields_warning(page):
|
||||
r.step("missing_fields_detected", "warn")
|
||||
return ApplicationResult(success=False, message=_("missing_fields"))
|
||||
elif await self.is_already_applied_warning(page):
|
||||
logger.warning(f"\t\talready applied warning detected")
|
||||
elif await self._already_applied_warning(page):
|
||||
r.step("already_applied_detected", "warn")
|
||||
return ApplicationResult(success=False, message=_("already_applied"))
|
||||
logger.warning(f"\t\tsubmit conformation not found")
|
||||
r.step("success.not_found", "warn")
|
||||
return ApplicationResult(success=False, message=_("submit_conformation_msg_not_found"))
|
||||
|
||||
async def is_already_applied_warning(self, page):
|
||||
async def _already_applied_warning(self, page) -> bool:
|
||||
await page.wait_for_timeout(1000)
|
||||
form_iframe = page.frame_locator("iframe[src*='wohnungshelden']")
|
||||
already_applied_warning = form_iframe.locator("span.ant-alert-message",
|
||||
has_text="Es existiert bereits eine Anfrage mit dieser E-Mail Adresse")
|
||||
if await already_applied_warning.first.is_visible():
|
||||
return True
|
||||
return False
|
||||
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 is_missing_fields_warning(self, page):
|
||||
async def _missing_fields_warning(self, page) -> bool:
|
||||
await page.wait_for_timeout(1000)
|
||||
form_iframe = page.frame_locator("iframe[src*='wohnungshelden']")
|
||||
already_applied_warning = form_iframe.locator("span.ant-alert-message",
|
||||
has_text="Es wurden nicht alle Felder korrekt befüllt. Bitte prüfen Sie ihre Eingaben")
|
||||
if await already_applied_warning.first.is_visible():
|
||||
return True
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
# url = "https://www.degewo.de/immosuche/details/neubau-mit-wbs-140-160-180-220-mit-besonderem-wohnbedarf-1" # already applied
|
||||
# url = "https://www.degewo.de/immosuche/details/wohnung-sucht-neuen-mieter-1" # angebot geschlossen
|
||||
# url = "https://www.degewo.de/immosuche/details/wohnung-sucht-neuen-mieter-145" # seite nicht gefunden
|
||||
# url = "https://www.degewo.de/immosuche/details/1-zimmer-mit-balkon-3"
|
||||
# url = "https://www.degewo.de/immosuche/details/2-zimmer-in-gropiusstadt-4"
|
||||
url = "https://www.degewo.de/immosuche/details/2-zimmer-in-gropiusstadt-4"
|
||||
provider = Degewo()
|
||||
provider.test_apply(url)
|
||||
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue