Skip to content

Commit

Permalink
Fixed Job State bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbbb committed Nov 27, 2024
1 parent 48e6c6c commit 19eaeee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
27 changes: 13 additions & 14 deletions src/ai_hawk/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']}")
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
12 changes: 2 additions & 10 deletions src/ai_hawk/linkedIn_easy_applier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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:
Expand Down

0 comments on commit 19eaeee

Please sign in to comment.