Skip to content

Commit

Permalink
misc: Touch-up for emojies
Browse files Browse the repository at this point in the history
  • Loading branch information
Vel-San committed Feb 19, 2024
1 parent fe13b99 commit aca17d5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 48 deletions.
12 changes: 4 additions & 8 deletions wbmbot_v2/helpers/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def send_email_notification(
if not constants.email_password:
LOG.warning(
color_me.yellow(
f"🚧 E-mail password not found in the ENV variables. I will not be able to send you e-mails!"
f"E-mail password not found in the ENV variables. I will not be able to send you e-mails 🚧"
)
)
return

if "@outlook.com" not in send_from:
LOG.warning(
color_me.yellow(
f"🚧 Notifications e-mail doesn't seem be of '@outlook.com' domain, skipping notifications!"
f"Notifications e-mail doesn't seem be of '@outlook.com' domain, skipping notifications 🚧"
)
)
return
Expand All @@ -56,11 +56,7 @@ def send_email_notification(
yag.send(to=send_to, subject=subject, contents=body)

LOG.info(
color_me.green(f"Email notification sent successfully to '{send_to}'")
color_me.green(f"Email notification sent successfully to '{send_to}'")
)
except Exception as e:
LOG.error(
color_me.red(
f"❌ Failed to send email notification to '{send_to}' | {str(e)}"
)
)
LOG.error(color_me.red(f"Failed to send email notification to '{send_to}' ❌"))
46 changes: 20 additions & 26 deletions wbmbot_v2/helpers/webDriverOperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,17 @@ def next_page(web_driver, current_page: int):
) # Adjust for non-page list items
LOG.info(
color_me.cyan(
f"Another page of flats was detected, switching to page {current_page + 1}/{total_pages}"
f"Another page of flats was detected, switching to page {current_page + 1}/{total_pages} 🔀"
)
)
next_page_button.click()
return current_page + 1
except NoSuchElementException as e:
# Log an error if the next page button is not found
LOG.error(color_me.red("Failed to switch page, last page reached"))
LOG.error(color_me.red("Failed to switch page, last page reached"))
except Exception as e:
# Log any other exceptions that occur
LOG.error(
color_me.red(
f"❌ Failed to switch page, returning to main page | Exception: {e}"
)
)
LOG.error(color_me.red(f"Failed to switch page, returning to main page ❌"))

# Return the current page number if navigation to the next page was not possible
return current_page
Expand All @@ -77,7 +73,7 @@ def download_expose_as_pdf(web_driver, flat_name: str):
"""

# Log the attempt to find the continue button
LOG.info(color_me.cyan(f"📥 Attempting to download expose for '{flat_name}'"))
LOG.info(color_me.cyan(f"Attempting to download expose for '{flat_name}' 📥"))

# Attempt to find the expose download button by its XPath
download_button = web_driver.find_element(
Expand All @@ -103,15 +99,15 @@ def ansehen_btn(web_driver, flat_element, index: int):

try:
# Log the attempt to find the ansehen button
LOG.info(color_me.cyan("🔎 Looking for 'Ansehen' button"))
LOG.info(color_me.cyan("Looking for 'Ansehen' button 🔎"))
# Attempt to find the ansehen button by its XPath
ansehen_button = flat_element.find_element(
By.XPATH, f"(//a[@title='Details'][contains(.,'Ansehen')])[{index+1}]"
)

# Log the href attribute of the found button
flat_link = ansehen_button.get_attribute("href")
LOG.info(color_me.green(f"🎯 Flat link found: {flat_link}"))
LOG.info(color_me.green(f"Flat link found: {flat_link} 🎯"))

# Scroll the button into view
ansehen_button.location_once_scrolled_into_view
Expand All @@ -121,10 +117,10 @@ def ansehen_btn(web_driver, flat_element, index: int):
return flat_link
except NoSuchElementException as e:
# Log an error if the Ansehen button is not found
LOG.error(color_me.red(f"'Ansehen' button not found. | {e}"))
LOG.error(color_me.red(f"'Ansehen' button not found"))
except StaleElementReferenceException as e:
# Log an error if the Ansehen button is stale
LOG.error(color_me.red(f"Stale 'Ansehen' button. | {e}"))
LOG.error(color_me.red(f"Stale 'Ansehen' button"))


def fill_form(web_driver, user_obj, email: str, test: str):
Expand All @@ -142,7 +138,7 @@ def fill_form(web_driver, user_obj, email: str, test: str):

try:
# Log the start of the form filling process
LOG.info(color_me.cyan(f"🤖 Filling out form for email address '{email}'"))
LOG.info(color_me.cyan(f"Filling out form for email address '{email}' 🤖"))

# If the user has WBS
if user_obj.wbs and not test:
Expand Down Expand Up @@ -227,9 +223,7 @@ def fill_form(web_driver, user_obj, email: str, test: str):
time.sleep(10) if test else None
except NoSuchElementException as e:
# Log an error if any element is not found
LOG.error(
color_me.red(f"❌ Element not found during form filling. Exception: {e}")
)
LOG.error(color_me.red(f"Element not found during form filling ❌"))


def accept_cookies(web_driver):
Expand All @@ -255,7 +249,7 @@ def accept_cookies(web_driver):

# Click the 'Accept Cookies' button
web_driver.find_element(By.XPATH, accept_button_xpath).click()
LOG.info(color_me.green("🍪 Cookies have been accepted"))
LOG.info(color_me.green("Cookies have been accepted 🍪"))
return True
except TimeoutException as e:
return False
Expand Down Expand Up @@ -366,7 +360,7 @@ def process_flats(

if not misc_operations.check_internet_connection():
LOG.error(
color_me.red("⚠️ No internet connection found. Retrying in 10 seconds!")
color_me.red("No internet connection found. Retrying in 10 seconds ⚠️")
)
time.sleep(10)
continue
Expand All @@ -380,14 +374,14 @@ def process_flats(
close_live_chat_button(web_driver)

# Find all flat offers displayed on current page
LOG.info(color_me.cyan("👀 Looking for flats"))
LOG.info(color_me.cyan("Looking for flats 👀"))
all_flats = find_flats(web_driver)
if not all_flats:
LOG.info(color_me.cyan("😔 Currently no flats available"))
LOG.info(color_me.cyan("Currently no flats available 😔"))
time.sleep(int(refresh_internal) * 60)
continue

LOG.info(color_me.green(f"💡 Found {len(all_flats)} flat(s) in total"))
LOG.info(color_me.green(f"Found {len(all_flats)} flat(s) in total 💡"))

# Save locally
if not test:
Expand Down Expand Up @@ -420,14 +414,14 @@ def process_flats(
)[0]:
LOG.warning(
color_me.yellow(
f"🙈 Ignoring flat '{flat_obj.title}' because it contains filter keyword(s) --> {misc_operations.contains_filter_keywords(flat_elem, user_profile.filter)[1]}"
f"Ignoring flat '{flat_obj.title}' because it contains filter keyword(s) --> {misc_operations.contains_filter_keywords(flat_elem, user_profile.filter)[1]} 🙈"
)
)
continue
else:
LOG.info(
color_me.cyan(
f"📩 Applying to flat: {flat_obj.title} for '{email}'"
f"Applying to flat: {flat_obj.title} for '{email}' 📩"
)
)
apply_to_flat(
Expand All @@ -442,7 +436,7 @@ def process_flats(
io_operations.write_log_file(
constants.log_file_path, email, flat_obj
)
LOG.info(color_me.green("Done!"))
LOG.info(color_me.green("Done"))
time.sleep(1.5)
web_driver.get(start_url)
time.sleep(1.5)
Expand All @@ -452,7 +446,7 @@ def process_flats(
else:
LOG.warning(
color_me.yellow(
f"🚫 Oops, we already applied for flat: {flat_obj.title}!"
f"Oops, we already applied for flat: {flat_obj.title} 🚫"
)
)
continue
Expand All @@ -468,4 +462,4 @@ def process_flats(
else:
time.sleep(1.5)

LOG.info(color_me.cyan("🔄 Reloading main page"))
LOG.info(color_me.cyan("Reloading main page 🔄"))
10 changes: 5 additions & 5 deletions wbmbot_v2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ def parse_args():
LOG = color_me.create_logger()

# Create ChromeDriver
LOG.info(color_me.cyan("🚀 Initializing Script"))
LOG.info(color_me.cyan("🔎 Checking for internet connection"))
LOG.info(color_me.cyan("Initializing Script 🚀"))
LOG.info(color_me.cyan("Checking for internet connection 🔎"))
while True:
if not misc_operations.check_internet_connection():
LOG.error(
color_me.red("⚠️ No internet connection found. Retrying in 10 seconds!")
color_me.red("No internet connection found. Retrying in 10 seconds ⚠️")
)
time.sleep(10)
else:
LOG.info(color_me.green("🟢 Online!"))
LOG.info(color_me.green("Online 🟢"))
break

chrome_driver_instance = cdc.ChromeDriverConfigurator(args.headless, args.test)
Expand All @@ -93,7 +93,7 @@ def parse_args():
current_page = 1
previous_page = 1
page_changed = False
LOG.info(color_me.cyan(f"🔗 Connecting to '{start_url}'"))
LOG.info(color_me.cyan(f"Connecting to '{start_url}' 🔗"))

webDriverOperations.process_flats(
web_driver,
Expand Down
2 changes: 1 addition & 1 deletion wbmbot_v2/utility/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def setup_wbm_config():
data["filter"] = []

# Log the completion of data collection
LOG.info(color_me.green("Done! Writing config file..."))
LOG.info(color_me.green("Done! Writing config file..."))

# Write the collected data to a JSON file
with open(constants.wbm_config_name, "w") as outfile:
Expand Down
16 changes: 8 additions & 8 deletions wbmbot_v2/utility/io_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ def load_wbm_config(file_name: str):
"""

if os.path.isfile(file_name):
LOG.info(color_me.cyan("⚙️ Loading WBM config"))
LOG.info(color_me.cyan("Loading WBM config ⚙️"))
with open(file_name, "r") as config_file:
try:
user_config = json.load(config_file)
return user_config
except json.JSONDecodeError as e:
LOG.error(color_me.red(f"Failed to parse WBM config file! ({e})"))
LOG.error(color_me.red(f"Failed to parse WBM config file"))
except TypeError as e:
LOG.error(color_me.red(f"Failed to parse WBM config file! ({e})"))
LOG.error(color_me.red(f"Failed to parse WBM config file"))
else:
LOG.warning(color_me.yellow("⚠️ No WBM config file found, starting setup"))
LOG.warning(color_me.yellow("No WBM config file found, starting setup ⚠️"))
# Setup WBM config from the User
interaction.setup_wbm_config()
LOG.info(color_me.cyan("⚙️ Loading WBM config"))
LOG.info(color_me.cyan("Loading WBM config ⚙️"))
with open(file_name, "r") as config_file:
try:
user_config = json.load(config_file)
return user_config
except json.JSONDecodeError as e:
LOG.error(color_me.red(f"Failed to parse WBM config file! ({e})"))
LOG.error(color_me.red(f"Failed to parse WBM config file"))
except TypeError as e:
LOG.error(color_me.red(f"Failed to parse WBM config file! ({e})"))
LOG.error(color_me.red(f"Failed to parse WBM config file"))


def initialize_application_logger(log_file: str):
Expand Down Expand Up @@ -131,7 +131,7 @@ def create_directory_if_not_exists(directory_path: str) -> None:
try:
os.makedirs(directory_path, exist_ok=True)
except OSError as e:
LOG.error(color_me.red(f"Error to create directory ({directory_path}): {e}"))
LOG.error(color_me.red(f"Error to create directory ({directory_path})"))


def check_flat_already_applied(log_file: str, email: str, flat_obj):
Expand Down

0 comments on commit aca17d5

Please sign in to comment.