Skip to content

Commit

Permalink
Now the program checks if the user is already logged in (#203)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Thomschke <[email protected]>
  • Loading branch information
Airwave1981 and sebthom authored Sep 17, 2023
1 parent 5c7729a commit b918bec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kleinanzeigen_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,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")]]]')
Expand Down Expand Up @@ -378,6 +382,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}']")
Expand Down

0 comments on commit b918bec

Please sign in to comment.