diff --git a/src/ai_hawk/job_manager.py b/src/ai_hawk/job_manager.py index a1f58526..e7fe01aa 100644 --- a/src/ai_hawk/job_manager.py +++ b/src/ai_hawk/job_manager.py @@ -5,6 +5,7 @@ from itertools import product from pathlib import Path import traceback +from turtle import color from inputimeout import inputimeout, TimeoutOccurred from selenium.common.exceptions import NoSuchElementException @@ -431,8 +432,7 @@ def get_base_search_url(self, parameters): if working_type_filter: url_parts.append(f"f_WT={'%2C'.join(working_type_filter)}") - experience_levels = [str(i + 1) for i, (level, v) in enumerate(parameters.get('experience_level', {}).items()) if - v] + experience_levels = [str(i + 1) for i, (level, v) in enumerate(parameters.get('experience_level', {}).items()) if v] if experience_levels: url_parts.append(f"f_E={','.join(experience_levels)}") url_parts.append(f"distance={parameters['distance']}") @@ -497,6 +497,17 @@ def job_tile_to_job(self, job_tile) -> Job: except NoSuchElementException: logger.warning("Job location is missing.") + # Extract job State + try: + job_state = job_tile.find_element( + By.XPATH, + ".//ul[contains(@class, 'job-card-list__footer-wrapper')]//li[contains(@class, 'job-card-container__footer-item')]", + ).text + logger.debug(f"Job state extracted: {job_state}") + job.apply_method = job_state + except NoSuchElementException as e: + logger.warning(f"Apply method and state not found. {e} {traceback.format_exc()}") + # Extract job ID from job url try: match = re.search(r'/jobs/view/(\d+)/', job.link) @@ -508,18 +519,6 @@ def job_tile_to_job(self, job_tile) -> Job: except Exception as e: logger.warning(f"Failed to extract job ID: {e}", exc_info=True) - # Extract job State - try: - job_state = job_tile.find_element(By.XPATH, ".//ul[contains(@class, 'job-card-list__footer-wrapper')]//li[contains(@class, 'job-card-container__footer-item')]").text - except NoSuchElementException as e: - try: - # Fetching state when apply method is not found - job_state = job_tile.find_element(By.XPATH, ".//ul[contains(@class, 'job-card-list__footer-wrapper')]//li[contains(@class, 'job-card-container__footer-job-state')]").text - job.apply_method = "Applied" - logger.warning(f'Apply method not found, state {job_state}. {e} {traceback.format_exc()}') - except NoSuchElementException as e: - logger.warning(f'Apply method and state not found. {e} {traceback.format_exc()}') - return job def is_blacklisted(self, job_title, company, link, job_location): diff --git a/src/ai_hawk/linkedIn_easy_applier.py b/src/ai_hawk/linkedIn_easy_applier.py index e5e7b6cb..db0eb594 100644 --- a/src/ai_hawk/linkedIn_easy_applier.py +++ b/src/ai_hawk/linkedIn_easy_applier.py @@ -178,7 +178,7 @@ def job_apply(self, job: Job): raise Exception(f"Failed to apply to job! Original exception:\nTraceback:\n{tb_str}") def _find_easy_apply_button(self, job_context: JobContext) -> WebElement: - logger.debug("Searching for 'Easy Apply' or 'Continue' button") + logger.debug("Searching for 'Easy Apply' button") attempt = 0 search_methods = [ @@ -194,15 +194,7 @@ def _find_easy_apply_button(self, job_context: JobContext) -> WebElement: { "description": "button text search", "xpath": '//button[contains(text(), "Easy Apply") or contains(text(), "Apply now")]', - }, - { - "description": "find 'Continue' button using text", - "xpath": '//button[.//span[text()="Continue"]]', - }, - { - "description": "find 'Continue' button using aria-label", - "xpath": '//button[contains(@aria-label, "Continue applying")]', - }, + } ] while attempt < 2: