From aca17d5f9b2195d6ac5cdbfc837213094c49f634 Mon Sep 17 00:00:00 2001 From: Vel-San <13340023+Vel-San@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:37:46 +0100 Subject: [PATCH] misc: Touch-up for emojies --- wbmbot_v2/helpers/notifications.py | 12 +++---- wbmbot_v2/helpers/webDriverOperations.py | 46 +++++++++++------------- wbmbot_v2/main.py | 10 +++--- wbmbot_v2/utility/interaction.py | 2 +- wbmbot_v2/utility/io_operations.py | 16 ++++----- 5 files changed, 38 insertions(+), 48 deletions(-) diff --git a/wbmbot_v2/helpers/notifications.py b/wbmbot_v2/helpers/notifications.py index 35a2293..18038e1 100644 --- a/wbmbot_v2/helpers/notifications.py +++ b/wbmbot_v2/helpers/notifications.py @@ -24,7 +24,7 @@ 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 @@ -32,7 +32,7 @@ def send_email_notification( 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 @@ -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}' ❌")) diff --git a/wbmbot_v2/helpers/webDriverOperations.py b/wbmbot_v2/helpers/webDriverOperations.py index a793b2a..1247acc 100644 --- a/wbmbot_v2/helpers/webDriverOperations.py +++ b/wbmbot_v2/helpers/webDriverOperations.py @@ -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 @@ -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( @@ -103,7 +99,7 @@ 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}]" @@ -111,7 +107,7 @@ def ansehen_btn(web_driver, flat_element, index: int): # 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 @@ -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): @@ -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: @@ -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): @@ -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 @@ -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 @@ -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: @@ -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( @@ -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) @@ -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 @@ -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 🔄")) diff --git a/wbmbot_v2/main.py b/wbmbot_v2/main.py index b22ca31..a5ad1ad 100755 --- a/wbmbot_v2/main.py +++ b/wbmbot_v2/main.py @@ -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) @@ -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, diff --git a/wbmbot_v2/utility/interaction.py b/wbmbot_v2/utility/interaction.py index 5de7101..95c4b84 100644 --- a/wbmbot_v2/utility/interaction.py +++ b/wbmbot_v2/utility/interaction.py @@ -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: diff --git a/wbmbot_v2/utility/io_operations.py b/wbmbot_v2/utility/io_operations.py index 88f44d7..08e432d 100644 --- a/wbmbot_v2/utility/io_operations.py +++ b/wbmbot_v2/utility/io_operations.py @@ -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): @@ -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):