diff --git a/kleinanzeigen_bot/__init__.py b/kleinanzeigen_bot/__init__.py index 57fd51e2..6559a8a2 100644 --- a/kleinanzeigen_bot/__init__.py +++ b/kleinanzeigen_bot/__init__.py @@ -349,6 +349,10 @@ def login(self) -> None: LOG.info("Logging in as [%s]...", self.config["login"]["username"]) self.web_open(f"{self.root_url}/m-einloggen.html?targetUrl=/") + if self.is_logged_in(): + LOG.info("Already logged in as [%s]. Skipping login.", self.config["login"]["username"]) + return + # close redesign banner try: self.web_click(By.XPATH, '//*[@id="pre-launch-comms-interstitial-frontend"]//button[.//*[text()[contains(.,"nicht mehr anzeigen")]]]') @@ -377,6 +381,16 @@ def login(self) -> None: except NoSuchElementException: pass + def is_logged_in(self) -> bool: + try: + user_email_elem = self.web_find(By.ID, "user-email") + email_text = user_email_elem.text + if f"angemeldet als: {self.config['login']['username']}" == email_text: + return True + except NoSuchElementException: + return False + return False + def handle_captcha_if_present(self, captcha_element_id:str, msg:str) -> None: try: self.web_click(By.XPATH, f"//*[@id='{captcha_element_id}']")