Skip to content

Commit

Permalink
Now the program checks if the user is already logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
Airwave1981 committed Aug 31, 2023
1 parent 51ef9c8 commit 85ca945
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 @@ -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")]]]')
Expand Down Expand Up @@ -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}']")
Expand Down

0 comments on commit 85ca945

Please sign in to comment.