From 8a042217cbd2debe70fdaf3904e6eb4896f67769 Mon Sep 17 00:00:00 2001 From: feder-cr Date: Mon, 5 Aug 2024 01:09:50 +0100 Subject: [PATCH] geenral fix --- gpt.py | 2 +- linkedIn_easy_applier.py | 19 ++++++++++++++----- linkedIn_job_manager.py | 29 +++++++++++++++-------------- utils.py | 14 ++++++++++++++ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/gpt.py b/gpt.py index 13832b5..b6f833d 100644 --- a/gpt.py +++ b/gpt.py @@ -224,7 +224,7 @@ class GPTAnswerer: } section_prompt = ( f"For the following question: '{question}', which section of the resume is relevant? " - "Respond with one of the following: Personal information, Self-Identification, Legal Authorization, " + "Respond with one of the following: Personal information, Self Identification, Legal Authorization, " "Work Preferences, Education Details, Experience Details, Projects, Availability, Salary Expectations, " "Certifications, Languages, Interests." ) diff --git a/linkedIn_easy_applier.py b/linkedIn_easy_applier.py index 75f9f35..51cb9c8 100644 --- a/linkedIn_easy_applier.py +++ b/linkedIn_easy_applier.py @@ -94,19 +94,24 @@ class LinkedInEasyApplier: def _fill_application_form(self): while True: self.fill_up() - self._next_or_submit() + if self._next_or_submit(): + break + def _next_or_submit(self): next_button = self.driver.find_element(By.CLASS_NAME, "artdeco-button--primary") button_text = next_button.text.lower() if 'submit application' in button_text: self._unfollow_company() + next_button.click() + return True time.sleep(random.uniform(1.5, 2.5)) next_button.click() time.sleep(random.uniform(3.0, 5.0)) self._check_for_errors() + def _unfollow_company(self) -> None: try: follow_checkbox = self.driver.find_element( @@ -130,10 +135,14 @@ class LinkedInEasyApplier: pass def fill_up(self) -> None: - easy_apply_content = self.driver.find_element(By.CLASS_NAME, 'jobs-easy-apply-content') - pb4_elements = easy_apply_content.find_elements(By.CLASS_NAME, 'pb4') - for element in pb4_elements: - self._process_form_element(element) + try: + easy_apply_content = self.driver.find_element(By.CLASS_NAME, 'jobs-easy-apply-content') + pb4_elements = easy_apply_content.find_elements(By.CLASS_NAME, 'pb4') + for element in pb4_elements: + self._process_form_element(element) + except Exception as e: + pass + def _process_form_element(self, element: WebElement) -> None: diff --git a/linkedIn_job_manager.py b/linkedIn_job_manager.py index 3867bf2..04833a4 100644 --- a/linkedIn_job_manager.py +++ b/linkedIn_job_manager.py @@ -80,41 +80,41 @@ class LinkedInJobManager: for position, location in searches: location_url = "&location=" + location job_page_number = -1 - print(f"Starting the search for {position} in {location}.") + utils.printyellow(f"Starting the search for {position} in {location}.") try: while True: page_sleep += 1 job_page_number += 1 - print(f"Going to job page {job_page_number}") + utils.printyellow(f"Going to job page {job_page_number}") self.next_job_page(position, location_url, job_page_number) time.sleep(random.uniform(1.5, 3.5)) - print("Starting the application process for this page...") + utils.printyellow("Starting the application process for this page...") self.apply_jobs() - print("Applying to jobs on this page has been completed!") + utils.printyellow("Applying to jobs on this page has been completed!") time_left = minimum_page_time - time.time() if time_left > 0: - print(f"Sleeping for {time_left} seconds.") + utils.printyellow(f"Sleeping for {time_left} seconds.") time.sleep(time_left) minimum_page_time = time.time() + minimum_time if page_sleep % 5 == 0: sleep_time = random.randint(5, 34) - print(f"Sleeping for {sleep_time / 60} minutes.") + utils.printyellow(f"Sleeping for {sleep_time / 60} minutes.") time.sleep(sleep_time) page_sleep += 1 except Exception: - traceback.print_exc() + traceback.format_exc() pass time_left = minimum_page_time - time.time() if time_left > 0: - print(f"Sleeping for {time_left} seconds.") + utils.printyellow(f"Sleeping for {time_left} seconds.") time.sleep(time_left) minimum_page_time = time.time() + minimum_time if page_sleep % 5 == 0: sleep_time = random.randint(50, 90) - print(f"Sleeping for {sleep_time / 60} minutes.") + utils.printyellow(f"Sleeping for {sleep_time / 60} minutes.") time.sleep(sleep_time) page_sleep += 1 @@ -140,20 +140,21 @@ class LinkedInJobManager: for job in job_list: if self.is_blacklisted(job.title, job.company, job.link): - print(f"Blacklisted {job.title} at {job.company}, skipping...") + utils.printyellow(f"Blacklisted {job.title} at {job.company}, skipping...") self.write_to_file(job.company, job.location, job.title, job.link, "skipped") continue try: if job.apply_method not in {"Continue", "Applied", "Apply"}: self.easy_applier_component.job_apply(job) - except Exception: + except Exception as e: + utils.printred(traceback.format_exc()) self.write_to_file(job.company, job.location, job.title, job.link, "failed") continue self.write_to_file(job.company, job.location, job.title, job.link, "success") except Exception as e: - traceback.print_exc() + traceback.format_exc() raise e def write_to_file(self, company, job_title, link, job_location, file_name): @@ -171,8 +172,8 @@ class LinkedInJobManager: writer = csv.writer(f) writer.writerow(to_write) except Exception as e: - print(f"Error writing registered job: {e}") - print(f"Details: Answer type: {answer_type}, Question: {question_text}") + utils.printred(f"Error writing registered job: {e}") + utils.printred(f"Details: Answer type: {answer_type}, Question: {question_text}") def get_base_search_url(self, parameters): remote_url = "f_CF=f_WRA" if parameters['remote'] else "" diff --git a/utils.py b/utils.py index 04d8fe9..1f2deb4 100644 --- a/utils.py +++ b/utils.py @@ -66,3 +66,17 @@ def chromeBrowserOptions(): else: options.add_argument("--incognito") return options + +def printred(text): + # Codice colore ANSI per il rosso + RED = "\033[91m" + RESET = "\033[0m" + # Stampa il testo in rosso + print(f"{RED}{text}{RESET}") + +def printyellow(text): + # Codice colore ANSI per il giallo + YELLOW = "\033[93m" + RESET = "\033[0m" + # Stampa il testo in giallo + print(f"{YELLOW}{text}{RESET}") \ No newline at end of file