Skip to content

Commit

Permalink
feat: Added support to ignore senior wonheims
Browse files Browse the repository at this point in the history
  • Loading branch information
Vel-San committed Mar 19, 2024
1 parent 95543e1 commit fbd1fc6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
4 changes: 3 additions & 1 deletion wbmbot_v2/handlers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def __init__(self, json_config):
self.sex = (
"Frau"
if self.config.get("sex", "") == "f"
else "Herr" if self.config.get("sex", "") == "m" else "Offen"
else "Herr"
if self.config.get("sex", "") == "m"
else "Offen"
)
self.street = self.config.get("street", "")
self.zip_code = self.config.get("zip_code", "")
Expand Down
2 changes: 1 addition & 1 deletion wbmbot_v2/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

# Bot version (MAJOR.MINOR.PATCH)
bot_version = "1.1.3"
bot_version = "1.1.4"

# Today
today = dt.date.today()
Expand Down
44 changes: 27 additions & 17 deletions wbmbot_v2/helpers/webDriverOperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ def apply_to_flat(

# Find and click "Ansehen" button on current flat
flat_link = ansehen_btn(web_driver, flat_element, flat_index)

if "seniorenwohnungen" in flat_link:
return False
# Fill out application form on current flat using info stored in user object
fill_form(web_driver, user_profile, email, test)

Expand All @@ -343,6 +344,8 @@ def apply_to_flat(
pdf_path,
)

return True


def process_flats(
web_driver,
Expand Down Expand Up @@ -448,12 +451,7 @@ def process_flats(
)
)
continue
LOG.info(
color_me.cyan(
f"Applying to flat: {flat_obj.title} for '{email}' 📩"
)
)
apply_to_flat(
applied = apply_to_flat(
web_driver,
flat_elem,
i,
Expand All @@ -462,16 +460,28 @@ def process_flats(
email,
test,
)
io_operations.write_log_file(
constants.log_file_path, email, flat_obj
)
LOG.info(color_me.green("Done ✅"))
time.sleep(1.5)
web_driver.get(start_url)
time.sleep(1.5)
# Refresh Flat Elements for each email iteration to avoid staleness
all_flats = find_flats(web_driver)
flat_elem = all_flats[i]
if applied:
LOG.info(
color_me.cyan(
f"Applying to flat: {flat_obj.title} for '{email}' 📩"
)
)
io_operations.write_log_file(
constants.log_file_path, email, flat_obj
)
LOG.info(color_me.green("Done ✅"))
time.sleep(1.5)
web_driver.get(start_url)
time.sleep(1.5)
# Refresh Flat Elements for each email iteration to avoid staleness
all_flats = find_flats(web_driver)
flat_elem = all_flats[i]
else:
LOG.warning(
color_me.yellow(
f"Ignoring flat: {flat_obj.title} because it is for Seniors only ('seniorenwohnungen') 🙈"
)
)
else:
LOG.warning(
color_me.yellow(
Expand Down
4 changes: 3 additions & 1 deletion wbmbot_v2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def main():
args.test,
)
except Exception as e:
LOG.error(color_me.red(f"Bot has crashed... Attempting to restart it now! ❤️‍🩹"))
LOG.error(
color_me.red(f"Bot has crashed... Attempting to restart it now! ❤️‍🩹")
)
LOG.error(color_me.red(f"Crash reason: {e}"))
# Wait for a few seconds before restarting
time.sleep(5)
Expand Down

0 comments on commit fbd1fc6

Please sign in to comment.