From 08af24ea3b616da9acd4a54690e01e74af42f5c9 Mon Sep 17 00:00:00 2001 From: Manu Altieri Date: Tue, 10 Sep 2024 21:16:00 +0200 Subject: [PATCH 01/11] added resume upload --- .DS_Store | Bin 0 -> 6148 bytes resume.pdf | Bin 0 -> 18810 bytes src/linkedin-api.py | 145 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 .DS_Store create mode 100644 resume.pdf diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f1a8e57f0d10732dc9e833146b222fb04be64e7d GIT binary patch literal 6148 zcmeHK%Wl&^6upy##vvd@0;IA)vcxtDX?PUGCQXw?C16n_SO5xkZCX>u6Ksc2MUk?H zZ{QbL^C9prtl-QeQtX5U8-(cG=*}6B@444=M)qWgi1jA^4pD=MEV#hRMKl{s+!wxP zB|UNp$YhR;(u0T}c@g*4qRoI&z$oyqDInh6EpjQvFQEMUD?SQ)@YYXh^3m($BRYc* z=?!s;a2-&x^41I1mjdg`W)^Y;^Z~g>G)AT%pM~8hWT~TK2!^PcQj6ZAxvi9ed zC$7>XI-q?T&=YcKkdI~`3pJ{E78g}wI?5C3Js2f(zstp_0XR}VHeY{rsx>AbzE2DLZPA)(}xeHD>HpUVX`{%+cKP3SD|T*0!D$n0%djC5c~h&_vimS z$y^x)i~|3a0<6+^`aMiZ@2zW-6ML-PXNwN7t8t+a RBQWzvK+0emqrhKP;1^65+amw~ literal 0 HcmV?d00001 diff --git a/resume.pdf b/resume.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c01805e89c1684e79130151abc23bb80401583a9 GIT binary patch literal 18810 zcmc({WmsIv+65XQKydc}jk~+M1r6@O-7UBi+}#~QZ~_E(cemhfA-KzJlF6LRnKS2n z_qjhV4SQF=rM*jd*Q!-bA}1_L!$8XfP13b>x^+-^mNnMZ1I-Me2UzQwL348h=%fs- zj2%n>EI^YyfKJrZ!okoEc(>4XFcdb_w>B^Y@bW_2J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*1^K?JgfiB#z_A+8yhp*-|Apv26AfumY0o<1-O>{wLEqP z=6^4bf$2ZmfD7hd^D;0oKacCbl*hot&i1!-z@hQCI@tdHOc~gi=zsehKq)LxvugL_ z`-~J!T@8U_13)KlZ4Es4^apJvVP#|uJOuTF!jcdM9)sd$HsoLi{)b@E)iq*ZVr1rE xH)3U>H)PW@Fl5y?&}TH_h5p}3fafTI`dE7h;JE)WC>hv+MM0C0h{%dU|35{Ppxgie literal 0 HcmV?d00001 diff --git a/src/linkedin-api.py b/src/linkedin-api.py index 37f727d..cb38de7 100644 --- a/src/linkedin-api.py +++ b/src/linkedin-api.py @@ -1,7 +1,7 @@ from typing import Dict, List from linkedin_api import Linkedin from typing import Optional, Union, Literal -from urllib.parse import quote, urlencode +from urllib.parse import quote, urlencode, parse_qs, urlparse import logging import json @@ -353,10 +353,134 @@ class LinkedInEvolvedAPI(Linkedin): # Push the commit to the repository and create a pull request to the v3 branch. + def create_request_pdf(self, filename: str) -> str | None: + """ + Create a PDF file with the request data. + :param filename: Name of the file + :type filename: str | None + :return: URL of the file uploaded to the LinkedIn. + """ + cookies = self.client.session.cookies.get_dict() + cookie_str = "; ".join([f"{k}={v}" for k, v in cookies.items()]) + + headers: Dict[str, str] = self._headers() + + + headers["Accept"] = "application/vnd.linkedin.normalized+json+2.1" + headers["csrf-token"] = cookies["JSESSIONID"].replace('"', "") + headers["Cookie"] = cookie_str + headers["Connection"] = "keep-alive" + + default_params = { + 'action': 'requestUrl' + } + + res = self._post( + f"/voyagerJobsDashAmbryUploadUrls", + headers=headers, + cookies=cookies, + json={"contentType":"PDF","filename":"200.pdf","maxSizeBytes":18810}, + params=default_params + ) + + + match res.status_code: + case 200: + parse_res = res.json() + url = parse_res['data']['value'] + logging.info(url) + return url + case _: + self.logger.error("Failed to create a request PDF") + return None + + def upload_resume_via_ambry(self, url: str, cv_path: str) -> bool | str: + """ + Upload resume via Ambry. + :param url: URL of the file uploaded to the LinkedIn. + :type url: str + :param raw_cv: Raw CV data + :type raw_cv: bytes + :return: PDF hash.pdf or false + """ + binary_cv: bytes = self.file_to_binary(cv_path) + + cookies = self.client.session.cookies.get_dict() + cookie_str = "; ".join([f"{k}={v}" for k, v in cookies.items()]) + + headers: Dict[str, str] = self._headers() + + headers["Accept"] = "application/vnd.linkedin.normalized+json+2.1" + headers["csrf-token"] = cookies["JSESSIONID"].replace('"', "") + headers["Cookie"] = cookie_str + headers["Connection"] = "keep-alive" + + ambry_url = url.replace("https://www.linkedin.com", "") + + res = self._post( + ambry_url, + base_request=True, + headers=headers, + cookies=cookies, + data=binary_cv, + ) + + match res.status_code: + case 201: + return res.headers['Location'] + case _: + self.logger.error("Failed to upload resume via Ambry") + return False + + def confirm_upload_resume(self, cv_hash: str) -> bool: + """ + Upload resume. + :param cv_hash: PDF hash + :type cv_hash: str + :return: True if success, False if failed + """ + + cookies = self.client.session.cookies.get_dict() + cookie_str = "; ".join([f"{k}={v}" for k, v in cookies.items()]) + + headers: Dict[str, str] = self._headers() + + headers["Accept"] = "application/vnd.linkedin.normalized+json+2.1" + headers["csrf-token"] = cookies["JSESSIONID"].replace('"', "") + headers["Cookie"] = cookie_str + headers["Connection"] = "keep-alive" + + json_data = {'entityUrn': f'urn:li:fsd_resume:{cv_hash}'} + res = self._post( + "/voyagerJobsDashResumes", + headers=headers, + cookies=cookies, + json=json_data, + ) + + match res.status_code: + case 201: + return True + case _: + self.logger.error("Failed to upload resume") + return False + + def file_to_binary(self, file_path): + with open(file_path, 'rb') as file: + binary_data = file.read() + return binary_data + def set_job_as_applied(self, job_id: str) -> None: self.already_applied_jobs.append(job_id) - + def upload_linkedin_resume(self, cv_path: str) -> str | bool: + url = self.create_request_pdf("resume.pdf") + if url: + cv_hash = self.upload_resume_via_ambry(url, cv_path) + if cv_hash: + self.confirm_upload_resume(cv_hash) + return cv_hash + return False @@ -364,12 +488,22 @@ class LinkedInEvolvedAPI(Linkedin): ## EXAMPLE USAGE if __name__ == "__main__": - api: LinkedInEvolvedAPI = LinkedInEvolvedAPI(username="", password="") + + api: LinkedInEvolvedAPI = LinkedInEvolvedAPI(username="", password="") jobs = api.search_jobs(keywords="Frontend Developer", location_name="Italia", limit=100, easy_apply=True, offset=1, listed_at=None) for job in jobs: job_id: str = job["job_id"] - print(f"Job ID: {job_id}") - continue + + resume: str = api.upload_linkedin_resume("resume.pdf") + if isinstance(resume, bool): + logging.error("Failed to upload resume") + continue + elif isinstance(resume, str): + logging.info(f"Resume uploaded with hash {resume}") + else: + logging.error("Unknown error") + continue + if job_id in api.already_applied_jobs: logging.info(f"Already applied to job {job_id}, skipping it") @@ -378,6 +512,7 @@ if __name__ == "__main__": fields = api.get_fields_for_easy_apply(job_id) for field in fields: print(field) + break From c85a2025f655801ac928cf4bd31bd209d26f5409 Mon Sep 17 00:00:00 2001 From: Manu Altieri Date: Tue, 10 Sep 2024 21:16:11 +0200 Subject: [PATCH 02/11] added resume upload --- resume.pdf | Bin 18810 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 resume.pdf diff --git a/resume.pdf b/resume.pdf deleted file mode 100644 index c01805e89c1684e79130151abc23bb80401583a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 18810 zcmc({WmsIv+65XQKydc}jk~+M1r6@O-7UBi+}#~QZ~_E(cemhfA-KzJlF6LRnKS2n z_qjhV4SQF=rM*jd*Q!-bA}1_L!$8XfP13b>x^+-^mNnMZ1I-Me2UzQwL348h=%fs- zj2%n>EI^YyfKJrZ!okoEc(>4XFcdb_w>B^Y@bW_2JJ=cOT0%R6q^l3cd=*7*+Mv4a z3qB5;hvSXZo)0r7C$^2~IB0Ap8<(-8)>=QCWEg z?0(nN9)Icelh)1Z%-7YCn!8Bzr7LUB?@sAwWnVpRAKciyREM|tXk}WdZJ1iAcRU+Y ztS3s55RR+%GoFsI8vX8ibE#DJC?B;TcXp_*oNZQGFA(f^LVK^QF5Mj2S!&#_HokIQ zT_@h{A@z*Z?-{e6<9G~-vQi5z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%dU|35{Ppxgie From d9ffc7542ce60fe915e91dd81779a3088cae10ec Mon Sep 17 00:00:00 2001 From: Manu Altieri Date: Tue, 10 Sep 2024 21:25:19 +0200 Subject: [PATCH 03/11] added resume upload --- src/linkedin-api.py | 138 ++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 76 deletions(-) diff --git a/src/linkedin-api.py b/src/linkedin-api.py index 3c007b2..cb38de7 100644 --- a/src/linkedin-api.py +++ b/src/linkedin-api.py @@ -1,66 +1,58 @@ -<<<<<<< HEAD from typing import Dict, List from linkedin_api import Linkedin from typing import Optional, Union, Literal from urllib.parse import quote, urlencode, parse_qs, urlparse -======= ->>>>>>> upstream/v3 import logging -from typing import Dict, List -from typing import Optional, Union, Literal -from urllib.parse import urlencode - -from linkedin_api import Linkedin +import json # set log to all debug logging.basicConfig(level=logging.INFO) - class LinkedInEvolvedAPI(Linkedin): already_applied_jobs: List[str] = [] - + def __init__(self, username, password): super().__init__(username, password) def search_jobs( - self, - keywords: Optional[str] = None, - companies: Optional[List[str]] = None, - experience: Optional[ - List[ - Union[ - Literal["1"], - Literal["2"], - Literal["3"], - Literal["4"], - Literal["5"], - Literal["6"], - ] + self, + keywords: Optional[str] = None, + companies: Optional[List[str]] = None, + experience: Optional[ + List[ + Union[ + Literal["1"], + Literal["2"], + Literal["3"], + Literal["4"], + Literal["5"], + Literal["6"], ] - ] = None, - job_type: Optional[ - List[ - Union[ - Literal["F"], - Literal["C"], - Literal["P"], - Literal["T"], - Literal["I"], - Literal["V"], - Literal["O"], - ] + ] + ] = None, + job_type: Optional[ + List[ + Union[ + Literal["F"], + Literal["C"], + Literal["P"], + Literal["T"], + Literal["I"], + Literal["V"], + Literal["O"], ] - ] = None, - job_title: Optional[List[str]] = None, - industries: Optional[List[str]] = None, - location_name: Optional[str] = None, - remote: Optional[List[Union[Literal["1"], Literal["2"], Literal["3"]]]] = None, - listed_at: None | int = None, - distance: Optional[int] = None, - easy_apply: Optional[bool] = True, - limit=-1, - offset=0, - **kwargs, + ] + ] = None, + job_title: Optional[List[str]] = None, + industries: Optional[List[str]] = None, + location_name: Optional[str] = None, + remote: Optional[List[Union[Literal["1"], Literal["2"], Literal["3"]]]] = None, + listed_at: None | int = None, + distance: Optional[int] = None, + easy_apply: Optional[bool] = True, + limit=-1, + offset=0, + **kwargs, ) -> List[Dict]: """Perform a LinkedIn search for jobs. @@ -162,21 +154,21 @@ class LinkedInEvolvedAPI(Linkedin): e["job_id"] = trackingUrn if e.get("$type") == "com.linkedin.voyager.dash.jobs.JobPosting": new_data.append(e) - + if not new_data: break results.extend(new_data) if ( - (-1 < limit <= len(results)) - or len(results) / count >= Linkedin._MAX_REPEATED_REQUESTS + (-1 < limit <= len(results)) + or len(results) / count >= Linkedin._MAX_REPEATED_REQUESTS ) or len(elements) == 0: break self.logger.debug(f"results grew to {len(results)}") return results - - def get_fields_for_easy_apply(self, job_id: str) -> List[Dict]: + + def get_fields_for_easy_apply(self,job_id: str) -> List[Dict]: """Get fields needed for easy apply jobs. :param job_id: Job ID @@ -189,12 +181,14 @@ class LinkedInEvolvedAPI(Linkedin): cookie_str = "; ".join([f"{k}={v}" for k, v in cookies.items()]) headers: Dict[str, str] = self._headers() + headers["Accept"] = "application/vnd.linkedin.normalized+json+2.1" headers["csrf-token"] = cookies["JSESSIONID"].replace('"', "") headers["Cookie"] = cookie_str headers["Connection"] = "keep-alive" + default_params = { "decorationId": "com.linkedin.voyager.dash.deco.jobs.OnsiteApplyApplication-67", "jobPostingUrn": f"urn:li:fsd_jobPosting:{job_id}", @@ -223,26 +217,26 @@ class LinkedInEvolvedAPI(Linkedin): except ValueError: self.logger.error("Failed to parse JSON response") return [] - + form_components = [] for item in data.get("included", []): - if 'formComponent' in item: + if 'formComponent' in item: urn = item['urn'] try: title = item['title']['text'] except TypeError: title = urn - + form_component_type = list(item['formComponent'].keys())[0] form_component_details = item['formComponent'][form_component_type] - + component_info = { 'title': title, 'urn': urn, 'formComponentType': form_component_type, } - + if 'textSelectableOptions' in form_component_details: options = [ opt['optionText']['text'] for opt in form_component_details['textSelectableOptions'] @@ -250,18 +244,18 @@ class LinkedInEvolvedAPI(Linkedin): component_info['selectableOptions'] = options elif 'selectableOptions' in form_component_details: options = [ - opt['textSelectableOption']['optionText']['text'] + opt['textSelectableOption']['optionText']['text'] for opt in form_component_details['selectableOptions'] ] component_info['selectableOptions'] = options - + form_components.append(component_info) return form_components - - def apply_to_job(self, job_id: str, fields: dict, followCompany: bool = True) -> bool: + + def apply_to_job(self,job_id: str, fields: dict, followCompany: bool = True) -> bool: return False - + # ToDo: Implement apply to job parser first # How need to be implemented: # 1. Get fields for easy apply job from the previous method (get_fields_for_easy_apply) @@ -271,11 +265,11 @@ class LinkedInEvolvedAPI(Linkedin): # {'title': 'Quanti anni di esperienza di lavoro hai con Router?', 'urn': 'urn:li:fsd_formElement:urn:li:jobs_applyformcommon_easyApplyFormElement:(4013860791,9478711764,numeric)', 'formComponentType': 'singleLineTextFormComponent', 'response': '5'} # To fill, you can temporary use input() function to get the data from the user manually for testing purposes (for the further implementation, the question will be asked to AI implementation and automatically filled) # Build a working payload. - + # EXAMPLE OF WORKING PAYLOAD # 4005350454 is job_id, so need to be replaced with the job_id - # { + #{ # "followCompany": true, # "responses": [ # { @@ -355,10 +349,9 @@ class LinkedInEvolvedAPI(Linkedin): # } # ], # "trackingId": "" - # } + #} # Push the commit to the repository and create a pull request to the v3 branch. -<<<<<<< HEAD def create_request_pdf(self, filename: str) -> str | None: """ @@ -476,13 +469,10 @@ class LinkedInEvolvedAPI(Linkedin): with open(file_path, 'rb') as file: binary_data = file.read() return binary_data -======= ->>>>>>> upstream/v3 def set_job_as_applied(self, job_id: str) -> None: self.already_applied_jobs.append(job_id) -<<<<<<< HEAD def upload_linkedin_resume(self, cv_path: str) -> str | bool: url = self.create_request_pdf("resume.pdf") if url: @@ -501,14 +491,6 @@ if __name__ == "__main__": api: LinkedInEvolvedAPI = LinkedInEvolvedAPI(username="", password="") jobs = api.search_jobs(keywords="Frontend Developer", location_name="Italia", limit=100, easy_apply=True, offset=1, listed_at=None) -======= - -## EXAMPLE USAGE -if __name__ == "__main__": - api: LinkedInEvolvedAPI = LinkedInEvolvedAPI(username="", password="") - jobs = api.search_jobs(keywords="Frontend Developer", location_name="Italia", limit=100, easy_apply=True, offset=1, - listed_at=None) ->>>>>>> upstream/v3 for job in jobs: job_id: str = job["job_id"] @@ -532,3 +514,7 @@ if __name__ == "__main__": print(field) break + + + + \ No newline at end of file From 5420b6b80dce5c666f1ef7573ef06d51607b80b2 Mon Sep 17 00:00:00 2001 From: Shivam Sareen Date: Tue, 10 Sep 2024 20:20:44 -0700 Subject: [PATCH 04/11] Resolved dependency conflict --- requirements.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 11127a8..9f271ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ langchain==0.2.11 langchain-community==0.2.10 -langchain-core==0.2.24 +langchain-core===0.2.36 langchain-openai==0.1.17 langchain-text-splitters==0.2.2 langsmith==0.1.93 @@ -14,9 +14,10 @@ click git+https://github.com/feder-cr/lib_resume_builder_AIHawk.git linkedin-api pdfminer.six==20221105 +jsonschema inputimeout==1.0.4 langchain-ollama==0.1.3 -langchain-anthropic==0.1.3 +langchain-anthropic langchain-google-genai==1.0.10 jsonschema==4.23.0 jsonschema-specifications==2023.12.1 From ff24e276c18c8230ac9e20cb57954f06436208e0 Mon Sep 17 00:00:00 2001 From: Shivam Sareen Date: Tue, 10 Sep 2024 22:01:21 -0700 Subject: [PATCH 05/11] Update gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c5c01ec..0a20e2e 100644 --- a/.gitignore +++ b/.gitignore @@ -152,4 +152,6 @@ mono_crash.* data_folder/output/* generated_cv/* chrome_profile/* -answers.json \ No newline at end of file +answers.json + +virtual/* \ No newline at end of file From a4846a8c6f4ee10e33928305cf5aefb82067ad49 Mon Sep 17 00:00:00 2001 From: blackms Date: Wed, 11 Sep 2024 18:48:46 +0200 Subject: [PATCH 06/11] First version with one issue of test suite --- requirements.txt | 1 + src/linkedIn_easy_applier.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/requirements.txt b/requirements.txt index 11127a8..dedcfa3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,4 @@ jsonschema-specifications==2023.12.1 httpx~=0.27.2 python-dotenv~=1.0.1 PyYAML~=6.0.2 +pytest>=8.3.3 diff --git a/src/linkedIn_easy_applier.py b/src/linkedIn_easy_applier.py index cf64245..1d734e8 100644 --- a/src/linkedIn_easy_applier.py +++ b/src/linkedIn_easy_applier.py @@ -76,6 +76,20 @@ class LinkedInEasyApplier: logger.error("Failed to return to job page after %d attempts. Cannot apply for the job.", max_attempts) raise Exception( f"Redirected to LinkedIn Premium page and failed to return after {max_attempts} attempts. Job application aborted.") + + def apply_to_job(self, job: Any) -> None: + """ + Starts the process of applying to a job. + :param job: A job object with the job details. + :return: None + """ + logger.debug(f"Applying to job: {job}") + try: + self.job_apply(job) + logger.info(f"Successfully applied to job: {job.title}") + except Exception as e: + logger.error(f"Failed to apply to job: {job.title}, error: {str(e)}") + raise e def job_apply(self, job: Any): logger.debug("Starting job application for job: %s", job) From 6eaf521db6b30af6863363ad4f5ef1ff166a723c Mon Sep 17 00:00:00 2001 From: blackms Date: Wed, 11 Sep 2024 18:52:17 +0200 Subject: [PATCH 07/11] Adding tests folder --- tests/__init__.py | 0 tests/test_job_application_profile.py | 153 +++++++++++++++++++++++ tests/test_linkedIn_authenticator.py | 158 ++++++++++++++++++++++++ tests/test_linkedIn_bot_facade.py | 14 +++ tests/test_linkedIn_easy_applier.py | 97 +++++++++++++++ tests/test_linkedIn_job_manager.py | 168 ++++++++++++++++++++++++++ tests/test_utils.py | 96 +++++++++++++++ 7 files changed, 686 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_job_application_profile.py create mode 100644 tests/test_linkedIn_authenticator.py create mode 100644 tests/test_linkedIn_bot_facade.py create mode 100644 tests/test_linkedIn_easy_applier.py create mode 100644 tests/test_linkedIn_job_manager.py create mode 100644 tests/test_utils.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_job_application_profile.py b/tests/test_job_application_profile.py new file mode 100644 index 0000000..91cc2a6 --- /dev/null +++ b/tests/test_job_application_profile.py @@ -0,0 +1,153 @@ +import pytest +from src.job_application_profile import JobApplicationProfile + +@pytest.fixture +def valid_yaml(): + """Valid YAML string for initializing JobApplicationProfile.""" + return """ + self_identification: + gender: Male + pronouns: He/Him + veteran: No + disability: No + ethnicity: Asian + legal_authorization: + eu_work_authorization: "Yes" + us_work_authorization: "Yes" + requires_us_visa: "No" + legally_allowed_to_work_in_us: "Yes" + requires_us_sponsorship: "No" + requires_eu_visa: "No" + legally_allowed_to_work_in_eu: "Yes" + requires_eu_sponsorship: "No" + work_preferences: + remote_work: "Yes" + in_person_work: "No" + open_to_relocation: "Yes" + willing_to_complete_assessments: "Yes" + willing_to_undergo_drug_tests: "Yes" + willing_to_undergo_background_checks: "Yes" + availability: + notice_period: "2 weeks" + salary_expectations: + salary_range_usd: "80000-120000" + """ + +@pytest.fixture +def missing_field_yaml(): + """YAML string missing a required field (self_identification).""" + return """ + legal_authorization: + eu_work_authorization: "Yes" + us_work_authorization: "Yes" + requires_us_visa: "No" + legally_allowed_to_work_in_us: "Yes" + requires_us_sponsorship: "No" + requires_eu_visa: "No" + legally_allowed_to_work_in_eu: "Yes" + requires_eu_sponsorship: "No" + work_preferences: + remote_work: "Yes" + in_person_work: "No" + open_to_relocation: "Yes" + willing_to_complete_assessments: "Yes" + willing_to_undergo_drug_tests: "Yes" + willing_to_undergo_background_checks: "Yes" + availability: + notice_period: "2 weeks" + salary_expectations: + salary_range_usd: "80000-120000" + """ + +@pytest.fixture +def invalid_type_yaml(): + """YAML string with an invalid type for a field.""" + return """ + self_identification: + gender: Male + pronouns: He/Him + veteran: No + disability: No + ethnicity: Asian + legal_authorization: + eu_work_authorization: "Yes" + us_work_authorization: "Yes" + requires_us_visa: "No" + legally_allowed_to_work_in_us: "Yes" + requires_us_sponsorship: "No" + requires_eu_visa: "No" + legally_allowed_to_work_in_eu: "Yes" + requires_eu_sponsorship: "No" + work_preferences: + remote_work: 12345 # Invalid type, expecting a string + in_person_work: "No" + open_to_relocation: "Yes" + willing_to_complete_assessments: "Yes" + willing_to_undergo_drug_tests: "Yes" + willing_to_undergo_background_checks: "Yes" + availability: + notice_period: "2 weeks" + salary_expectations: + salary_range_usd: "80000-120000" + """ + +def test_initialize_with_valid_yaml(valid_yaml): + """Test initializing JobApplicationProfile with valid YAML.""" + profile = JobApplicationProfile(valid_yaml) + + # Check that the profile fields are correctly initialized + assert profile.self_identification.gender == "Male" + assert profile.self_identification.pronouns == "He/Him" + assert profile.legal_authorization.eu_work_authorization == "Yes" + assert profile.work_preferences.remote_work == "Yes" + assert profile.availability.notice_period == "2 weeks" + assert profile.salary_expectations.salary_range_usd == "80000-120000" + +def test_initialize_with_missing_field(missing_field_yaml): + """Test initializing JobApplicationProfile with missing required fields.""" + with pytest.raises(KeyError) as excinfo: + JobApplicationProfile(missing_field_yaml) + assert "self_identification" in str(excinfo.value) + +def test_initialize_with_invalid_yaml(): + """Test initializing JobApplicationProfile with invalid YAML.""" + invalid_yaml_str = """ + self_identification: + gender: Male + pronouns: He/Him + veteran: No + disability: No + ethnicity: Asian + legal_authorization: + eu_work_authorization: "Yes" + us_work_authorization: "Yes" + requires_us_visa: "No" + legally_allowed_to_work_in_us: "Yes" + requires_us_sponsorship: "No" + requires_eu_visa: "No" + legally_allowed_to_work_in_eu: "Yes" + requires_eu_sponsorship: "No" + work_preferences: + remote_work: "Yes" + in_person_work: "No" + availability: + notice_period: "2 weeks" + salary_expectations: + salary_range_usd: "80000-120000" + """ # Missing fields in work_preferences + + with pytest.raises(TypeError): + JobApplicationProfile(invalid_yaml_str) + +def test_str_representation(valid_yaml): + """Test the string representation of JobApplicationProfile.""" + profile = JobApplicationProfile(valid_yaml) + profile_str = str(profile) + + assert "Self Identification:" in profile_str + assert "Legal Authorization:" in profile_str + assert "Work Preferences:" in profile_str + assert "Availability:" in profile_str + assert "Salary Expectations:" in profile_str + assert "Male" in profile_str + assert "80000-120000" in profile_str diff --git a/tests/test_linkedIn_authenticator.py b/tests/test_linkedIn_authenticator.py new file mode 100644 index 0000000..6277fc0 --- /dev/null +++ b/tests/test_linkedIn_authenticator.py @@ -0,0 +1,158 @@ +import pytest +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from src.linkedIn_authenticator import LinkedInAuthenticator +from selenium.common.exceptions import NoSuchElementException, TimeoutException + + +@pytest.fixture +def mock_driver(mocker): + """Fixture to mock the Selenium WebDriver.""" + return mocker.Mock() + + +@pytest.fixture +def authenticator(mock_driver): + """Fixture to initialize LinkedInAuthenticator with a mocked driver.""" + return LinkedInAuthenticator(mock_driver) + + +def test_set_secrets(authenticator): + """Test setting secrets (email, password).""" + authenticator.set_secrets("test@example.com", "password123") + assert authenticator.email == "test@example.com" + assert authenticator.password == "password123" + + +def test_start_logged_in(mocker, authenticator): + """Test starting LinkedIn when already logged in.""" + mocker.patch.object(authenticator, 'is_logged_in', return_value=True) + mocker.patch.object(authenticator.driver, 'get') + mocker.patch("time.sleep") # Avoid waiting during the test + + authenticator.start() + + authenticator.driver.get.assert_called_with('https://www.linkedin.com/feed') + authenticator.is_logged_in.assert_called_once() + assert authenticator.driver.get.call_count == 1 + + +def test_start_not_logged_in(mocker, authenticator): + """Test starting LinkedIn when not logged in.""" + mocker.patch.object(authenticator, 'is_logged_in', return_value=False) + mocker.patch.object(authenticator, 'handle_login') + mocker.patch.object(authenticator.driver, 'get') + mocker.patch("time.sleep") + + authenticator.start() + + authenticator.driver.get.assert_called_with('https://www.linkedin.com/feed') + authenticator.handle_login.assert_called_once() + + +def test_handle_login(mocker, authenticator): + """Test handling the LinkedIn login process.""" + mocker.patch.object(authenticator.driver, 'get') + mocker.patch.object(authenticator, 'enter_credentials') + mocker.patch.object(authenticator, 'submit_login_form') + mocker.patch.object(authenticator, 'handle_security_check') + + # Mock current_url as a regular return value, not PropertyMock + mocker.patch.object(authenticator.driver, 'current_url', return_value='https://www.linkedin.com/login') + + authenticator.handle_login() + + authenticator.driver.get.assert_called_with('https://www.linkedin.com/login') + authenticator.enter_credentials.assert_called_once() + authenticator.submit_login_form.assert_called_once() + authenticator.handle_security_check.assert_called_once() + + +def test_enter_credentials_success(mocker, authenticator): + """Test entering credentials.""" + email_mock = mocker.Mock() + password_mock = mocker.Mock() + + mocker.patch.object(WebDriverWait, 'until', return_value=email_mock) + mocker.patch.object(authenticator.driver, 'find_element', return_value=password_mock) + + authenticator.set_secrets("test@example.com", "password123") + authenticator.enter_credentials() + + email_mock.send_keys.assert_called_once_with("test@example.com") + password_mock.send_keys.assert_called_once_with("password123") + + +def test_enter_credentials_timeout(mocker, authenticator): + """Test entering credentials with a TimeoutException.""" + mocker.patch.object(WebDriverWait, 'until', side_effect=TimeoutException) + + authenticator.set_secrets("test@example.com", "password123") + + authenticator.enter_credentials() + + authenticator.driver.find_element.assert_not_called() # Password input should not be accessed if email fails + + +def test_submit_login_form_success(mocker, authenticator): + """Test submitting the login form.""" + login_button_mock = mocker.Mock() + mocker.patch.object(authenticator.driver, 'find_element', return_value=login_button_mock) + + authenticator.submit_login_form() + + login_button_mock.click.assert_called_once() + + +def test_submit_login_form_no_button(mocker, authenticator): + """Test submitting the login form when the login button is not found.""" + mocker.patch.object(authenticator.driver, 'find_element', side_effect=NoSuchElementException) + + authenticator.submit_login_form() + + authenticator.driver.find_element.assert_called_once_with(By.XPATH, '//button[@type="submit"]') + + +def test_is_logged_in_true(mocker, authenticator): + """Test if the user is logged in.""" + buttons_mock = mocker.Mock() + buttons_mock.text = "Start a post" + mocker.patch.object(WebDriverWait, 'until') + mocker.patch.object(authenticator.driver, 'find_elements', return_value=[buttons_mock]) + + assert authenticator.is_logged_in() is True + + +def test_is_logged_in_false(mocker, authenticator): + """Test if the user is not logged in.""" + mocker.patch.object(WebDriverWait, 'until') + mocker.patch.object(authenticator.driver, 'find_elements', return_value=[]) + + assert authenticator.is_logged_in() is False + + +def test_handle_security_check_success(mocker, authenticator): + """Test handling security check successfully.""" + mocker.patch.object(WebDriverWait, 'until', side_effect=[ + mocker.Mock(), # Security checkpoint detection + mocker.Mock() # Security check completion + ]) + + authenticator.handle_security_check() + + # Verify WebDriverWait is called with EC.url_contains for both the challenge and feed + WebDriverWait(authenticator.driver, 10).until.assert_any_call(mocker.ANY) + WebDriverWait(authenticator.driver, 300).until.assert_any_call(mocker.ANY) + + + +def test_handle_security_check_timeout(mocker, authenticator): + """Test handling security check timeout.""" + mocker.patch.object(WebDriverWait, 'until', side_effect=TimeoutException) + + authenticator.handle_security_check() + + # Verify WebDriverWait is called with EC.url_contains for the challenge + WebDriverWait(authenticator.driver, 10).until.assert_any_call(mocker.ANY) + diff --git a/tests/test_linkedIn_bot_facade.py b/tests/test_linkedIn_bot_facade.py new file mode 100644 index 0000000..787d99a --- /dev/null +++ b/tests/test_linkedIn_bot_facade.py @@ -0,0 +1,14 @@ +import pytest +# from src.linkedIn_job_manager import JobManager + +@pytest.fixture +def job_manager(): + """Fixture for JobManager.""" + return None # Replace with valid instance or mock later + +def test_bot_functionality(job_manager): + """Test LinkedIn bot facade.""" + # Example: test job manager interacts with the bot facade correctly + job = {"title": "Software Engineer"} + # job_manager.some_method_to_apply(job) + assert job is not None # Placeholder for actual test diff --git a/tests/test_linkedIn_easy_applier.py b/tests/test_linkedIn_easy_applier.py new file mode 100644 index 0000000..7000a41 --- /dev/null +++ b/tests/test_linkedIn_easy_applier.py @@ -0,0 +1,97 @@ +import pytest +from unittest import mock +from src.linkedIn_easy_applier import LinkedInEasyApplier + + +@pytest.fixture +def mock_driver(): + """Fixture to mock Selenium WebDriver.""" + return mock.Mock() + + +@pytest.fixture +def mock_gpt_answerer(): + """Fixture to mock GPT Answerer.""" + return mock.Mock() + + +@pytest.fixture +def mock_resume_generator_manager(): + """Fixture to mock Resume Generator Manager.""" + return mock.Mock() + + +@pytest.fixture +def easy_applier(mock_driver, mock_gpt_answerer, mock_resume_generator_manager): + """Fixture to initialize LinkedInEasyApplier with mocks.""" + return LinkedInEasyApplier( + driver=mock_driver, + resume_dir="/path/to/resume", + set_old_answers=[('Question 1', 'Answer 1', 'Type 1')], + gpt_answerer=mock_gpt_answerer, + resume_generator_manager=mock_resume_generator_manager + ) + + +def test_initialization(mocker, easy_applier): + """Test that LinkedInEasyApplier is initialized correctly.""" + # Mock os.path.exists to return True + mocker.patch('os.path.exists', return_value=True) + + easy_applier = LinkedInEasyApplier( + driver=mocker.Mock(), + resume_dir="/path/to/resume", + set_old_answers=[('Question 1', 'Answer 1', 'Type 1')], + gpt_answerer=mocker.Mock(), + resume_generator_manager=mocker.Mock() + ) + + assert easy_applier.resume_path == "/path/to/resume" + assert len(easy_applier.set_old_answers) == 1 + assert easy_applier.gpt_answerer is not None + assert easy_applier.resume_generator_manager is not None + + +def test_apply_to_job_success(mocker, easy_applier): + """Test successfully applying to a job.""" + mock_job = mock.Mock() + + # Mock job_apply so we don't actually try to apply + mocker.patch.object(easy_applier, 'job_apply') + + easy_applier.apply_to_job(mock_job) + easy_applier.job_apply.assert_called_once_with(mock_job) + + +def test_apply_to_job_failure(mocker, easy_applier): + """Test failure while applying to a job.""" + mock_job = mock.Mock() + mocker.patch.object(easy_applier, 'job_apply', + side_effect=Exception("Test error")) + + with pytest.raises(Exception, match="Test error"): + easy_applier.apply_to_job(mock_job) + + easy_applier.job_apply.assert_called_once_with(mock_job) + + +def test_check_for_premium_redirect_no_redirect(mocker, easy_applier): + """Test that check_for_premium_redirect works when there's no redirect.""" + mock_job = mock.Mock() + easy_applier.driver.current_url = "https://www.linkedin.com/jobs/view/1234" + + easy_applier.check_for_premium_redirect(mock_job) + easy_applier.driver.get.assert_not_called() + + +def test_check_for_premium_redirect_with_redirect(mocker, easy_applier): + """Test that check_for_premium_redirect handles LinkedIn Premium redirects.""" + mock_job = mock.Mock() + easy_applier.driver.current_url = "https://www.linkedin.com/premium" + mock_job.link = "https://www.linkedin.com/jobs/view/1234" + + with pytest.raises(Exception, match="Redirected to LinkedIn Premium page and failed to return"): + easy_applier.check_for_premium_redirect(mock_job) + + # Verify that it attempted to return to the job page 3 times + assert easy_applier.driver.get.call_count == 3 diff --git a/tests/test_linkedIn_job_manager.py b/tests/test_linkedIn_job_manager.py new file mode 100644 index 0000000..0b4121e --- /dev/null +++ b/tests/test_linkedIn_job_manager.py @@ -0,0 +1,168 @@ +from src.job import Job +from unittest import mock +from pathlib import Path +import os +import pytest +from src.linkedIn_job_manager import LinkedInJobManager +from selenium.common.exceptions import NoSuchElementException + + +@pytest.fixture +def job_manager(mocker): + """Fixture to create a LinkedInJobManager instance with mocked driver.""" + mock_driver = mocker.Mock() + return LinkedInJobManager(mock_driver) + + +def test_initialization(job_manager): + """Test LinkedInJobManager initialization.""" + assert job_manager.driver is not None + assert job_manager.set_old_answers == set() + assert job_manager.easy_applier_component is None + + +def test_set_parameters(mocker, job_manager): + """Test setting parameters for the LinkedInJobManager.""" + # Mocking os.path.exists to return True for the resume path + mocker.patch('pathlib.Path.exists', return_value=True) + + params = { + 'company_blacklist': ['Company A', 'Company B'], + 'title_blacklist': ['Intern', 'Junior'], + 'positions': ['Software Engineer', 'Data Scientist'], + 'locations': ['New York', 'San Francisco'], + 'apply_once_at_company': True, + 'uploads': {'resume': '/path/to/resume'}, # Resume path provided here + 'outputFileDirectory': '/path/to/output', + 'job_applicants_threshold': { + 'min_applicants': 5, + 'max_applicants': 50 + }, + 'remote': False, + 'distance': 50, + 'date': {'all time': True} + } + + job_manager.set_parameters(params) + + # Normalize paths to handle platform differences (e.g., Windows vs Unix-like systems) + assert str(job_manager.resume_path) == os.path.normpath('/path/to/resume') + assert str(job_manager.output_file_directory) == os.path.normpath( + '/path/to/output') + + +def next_job_page(self, position, location, job_page): + logger.debug("Navigating to next job page: %s in %s, page %d", + position, location, job_page) + self.driver.get( + f"https://www.linkedin.com/jobs/search/{self.base_search_url}&keywords={position}&location={location}&start={job_page * 25}") + + +def test_get_jobs_from_page_no_jobs(mocker, job_manager): + """Test get_jobs_from_page when no jobs are found.""" + mocker.patch.object(job_manager.driver, 'find_element', + side_effect=NoSuchElementException) + + jobs = job_manager.get_jobs_from_page() + assert jobs == [] + + +def test_get_jobs_from_page_with_jobs(mocker, job_manager): + """Test get_jobs_from_page when job elements are found.""" + # Mock the no_jobs_element to behave correctly + mock_no_jobs_element = mocker.Mock() + mock_no_jobs_element.text = "No matching jobs found" + + # Mocking the find_element to return the mock no_jobs_element + mocker.patch.object(job_manager.driver, 'find_element', + return_value=mock_no_jobs_element) + + # Mock the page_source + mocker.patch.object(job_manager.driver, 'page_source', + return_value="some page content") + + # Ensure jobs are returned as empty list due to "No matching jobs found" + jobs = job_manager.get_jobs_from_page() + assert jobs == [] # No jobs expected due to "No matching jobs found" + + +def test_apply_jobs_with_no_jobs(mocker, job_manager): + """Test apply_jobs when no jobs are found.""" + # Mocking find_element to return a mock element that simulates no jobs + mock_element = mocker.Mock() + mock_element.text = "No matching jobs found" + + # Mock the driver to simulate the page source + mocker.patch.object(job_manager.driver, 'page_source', return_value="") + + # Mock the driver to return the mock element when find_element is called + mocker.patch.object(job_manager.driver, 'find_element', + return_value=mock_element) + + # Call apply_jobs and ensure no exceptions are raised + job_manager.apply_jobs() + + # Ensure it attempted to find the job results list + assert job_manager.driver.find_element.call_count == 1 + + +def test_apply_jobs_with_jobs(mocker, job_manager): + """Test apply_jobs when jobs are present.""" + + # Mock no_jobs_element to simulate the absence of "No matching jobs found" banner + no_jobs_element = mocker.Mock() + no_jobs_element.text = "" # Empty text means "No matching jobs found" is not present + mocker.patch.object(job_manager.driver, 'find_element', + return_value=no_jobs_element) + + # Mock the page_source to simulate what the page looks like when jobs are present + mocker.patch.object(job_manager.driver, 'page_source', + return_value="some job content") + + # Mock the outer find_elements (scaffold-layout__list-container) + container_mock = mocker.Mock() + + # Mock the inner find_elements to return job list items + job_element_mock = mocker.Mock() + # Simulating two job items + job_elements_list = [job_element_mock, job_element_mock] + + # Return the container mock, which itself returns the job elements list + container_mock.find_elements.return_value = job_elements_list + mocker.patch.object(job_manager.driver, 'find_elements', + return_value=[container_mock]) + + # Mock the extract_job_information_from_tile method to return sample job info + mocker.patch.object(job_manager, 'extract_job_information_from_tile', return_value=( + "Title", "Company", "Location", "Apply", "Link")) + + # Mock other methods like is_blacklisted, is_already_applied_to_job, and is_already_applied_to_company + mocker.patch.object(job_manager, 'is_blacklisted', return_value=False) + mocker.patch.object( + job_manager, 'is_already_applied_to_job', return_value=False) + mocker.patch.object( + job_manager, 'is_already_applied_to_company', return_value=False) + + # Mock the LinkedInEasyApplier component + job_manager.easy_applier_component = mocker.Mock() + + # Mock the output_file_directory as a valid Path object + job_manager.output_file_directory = Path("/mocked/path/to/output") + + # Mock Path.exists() to always return True (so no actual file system interaction is needed) + mocker.patch.object(Path, 'exists', return_value=True) + + # Mock the open function to prevent actual file writing + mock_open = mocker.mock_open() + mocker.patch('builtins.open', mock_open) + + # Run the apply_jobs method + job_manager.apply_jobs() + + # Assertions + assert job_manager.driver.find_elements.call_count == 1 + # Called for each job element + assert job_manager.extract_job_information_from_tile.call_count == 2 + # Called for each job element + assert job_manager.easy_applier_component.job_apply.call_count == 2 + mock_open.assert_called() # Ensure that the open function was called diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..efe3645 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,96 @@ +# tests/test_utils.py +import pytest +import os +import time +from unittest import mock +from selenium.webdriver.remote.webelement import WebElement +from src.utils import ensure_chrome_profile, is_scrollable, scroll_slow, chrome_browser_options, printred, printyellow + +# Mocking logging to avoid actual file writing +@pytest.fixture(autouse=True) +def mock_logger(mocker): + mocker.patch("src.utils.logger") + +# Test ensure_chrome_profile function +def test_ensure_chrome_profile(mocker): + mocker.patch("os.path.exists", return_value=False) # Pretend directory doesn't exist + mocker.patch("os.makedirs") # Mock making directories + + # Call the function + profile_path = ensure_chrome_profile() + + # Verify that os.makedirs was called twice to create the directory + assert profile_path.endswith("linkedin_profile") + assert os.path.exists.called + assert os.makedirs.called + +# Test is_scrollable function +def test_is_scrollable(mocker): + mock_element = mocker.Mock(spec=WebElement) + mock_element.get_attribute.side_effect = lambda attr: "1000" if attr == "scrollHeight" else "500" + + # Call the function + scrollable = is_scrollable(mock_element) + + # Check the expected outcome + assert scrollable is True + mock_element.get_attribute.assert_any_call("scrollHeight") + mock_element.get_attribute.assert_any_call("clientHeight") + +# Test scroll_slow function +def test_scroll_slow(mocker): + mock_driver = mocker.Mock() + mock_element = mocker.Mock(spec=WebElement) + + # Mock element's attributes for scrolling + mock_element.get_attribute.side_effect = lambda attr: "2000" if attr == "scrollHeight" else "0" + mock_element.is_displayed.return_value = True + mocker.patch("time.sleep") # Mock time.sleep to avoid waiting + + # Call the function + scroll_slow(mock_driver, mock_element, start=0, end=1000, step=100, reverse=False) + + # Ensure that scrolling happened multiple times + assert mock_driver.execute_script.called + mock_element.is_displayed.assert_called_once() + +def test_scroll_slow_element_not_scrollable(mocker): + mock_driver = mocker.Mock() + mock_element = mocker.Mock(spec=WebElement) + + # Mock the attributes so the element is not scrollable + mock_element.get_attribute.side_effect = lambda attr: "1000" if attr == "scrollHeight" else "1000" + mock_element.is_displayed.return_value = True + + scroll_slow(mock_driver, mock_element, start=0, end=1000, step=100) + + # Ensure it detected non-scrollable element + mock_driver.execute_script.assert_not_called() + +# Test chrome_browser_options function +def test_chrome_browser_options(mocker): + mocker.patch("src.utils.ensure_chrome_profile") + mocker.patch("os.path.dirname", return_value="/mocked/path") + mocker.patch("os.path.basename", return_value="profile_directory") + + mock_options = mocker.Mock() + + mocker.patch("selenium.webdriver.ChromeOptions", return_value=mock_options) + + # Call the function + options = chrome_browser_options() + + # Ensure options were set + assert mock_options.add_argument.called + assert options == mock_options + +# Test printred and printyellow functions +def test_printred(mocker): + mocker.patch("builtins.print") + printred("Test") + print.assert_called_once_with("\033[91mTest\033[0m") + +def test_printyellow(mocker): + mocker.patch("builtins.print") + printyellow("Test") + print.assert_called_once_with("\033[93mTest\033[0m") From 2c1322b27087762cedff1b61e6bad2816ee249cb Mon Sep 17 00:00:00 2001 From: blackms Date: Wed, 11 Sep 2024 19:01:29 +0200 Subject: [PATCH 08/11] pytest config missing --- pytest.ini | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..b58955c --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +minversion = 6.0 +addopts = --strict-markers --tb=short --cov=src --cov-report=term-missing +testpaths = + tests \ No newline at end of file From 82fc6beddecf41895b745d56585a8c03b0d5d53d Mon Sep 17 00:00:00 2001 From: queukat Date: Fri, 13 Sep 2024 02:32:23 +0300 Subject: [PATCH 09/11] fixed easy apply button, make some refactoring and fixed saiving cover letters --- src/linkedIn_easy_applier.py | 161 ++++++++++++++++++++++++++--------- src/linkedIn_job_manager.py | 127 ++++++++++++--------------- src/utils.py | 5 ++ 3 files changed, 181 insertions(+), 112 deletions(-) diff --git a/src/linkedIn_easy_applier.py b/src/linkedIn_easy_applier.py index 1d734e8..dd33beb 100644 --- a/src/linkedIn_easy_applier.py +++ b/src/linkedIn_easy_applier.py @@ -24,7 +24,7 @@ from src.utils import logger class LinkedInEasyApplier: def __init__(self, driver: Any, resume_dir: Optional[str], set_old_answers: List[Tuple[str, str, str]], - gpt_answerer: Any, resume_generator_manager): + gpt_answerer: Any, resume_generator_manager, parameters: dict): logger.debug("Initializing LinkedInEasyApplier") if resume_dir is None or not os.path.exists(resume_dir): resume_dir = None @@ -125,10 +125,20 @@ class LinkedInEasyApplier: job.set_recruiter_link(recruiter_link) logger.debug("Recruiter link set: %s", recruiter_link) - logger.debug("Attempting to click 'Easy Apply' button") - actions = ActionChains(self.driver) - actions.move_to_element(easy_apply_button).click().perform() - logger.debug("'Easy Apply' button clicked successfully") + # Try clicking the "Easy Apply" button + try: + logger.debug("Attempting to click 'Easy Apply' button using ActionChains") + actions = ActionChains(self.driver) + actions.move_to_element(easy_apply_button).click().perform() + logger.debug("'Easy Apply' button clicked successfully") + except Exception as e: + logger.warning(f"Failed to click 'Easy Apply' button using ActionChains: {e}, trying JavaScript click") + try: + self.driver.execute_script("arguments[0].click();", easy_apply_button) + logger.debug("'Easy Apply' button clicked successfully via JavaScript") + except Exception as js_error: + logger.error(f"Failed to click 'Easy Apply' button via JavaScript: {js_error}") + raise logger.debug("Passing job information to GPT Answerer") self.gpt_answerer.set_job(job) @@ -150,73 +160,112 @@ class LinkedInEasyApplier: def _find_easy_apply_button(self, job: Any) -> WebElement: logger.debug("Searching for 'Easy Apply' button") attempt = 0 + timeout = 8 search_methods = [ + { + 'description': "'aria-label' containing 'Easy Apply to' and with data-job-id attribute", + 'xpath': '//button[contains(@aria-label, "Easy Apply to") and contains(@data-job-id, "")]' + }, { 'description': "find all 'Easy Apply' buttons using find_elements", 'find_elements': True, - 'xpath': '//button[contains(@class, "jobs-apply-button") and contains(., "Easy Apply")]' + 'xpath': '//button[contains(@class, "jobs-apply-button") and contains(., "Easy Apply") and contains(@data-job-id, "")]' }, { - 'description': "'aria-label' containing 'Easy Apply to'", - 'xpath': '//button[contains(@aria-label, "Easy Apply to")]' - }, - { - 'description': "button text search", - 'xpath': '//button[contains(text(), "Easy Apply") or contains(text(), "Apply now")]' + 'description': "button text search with data-job-id attribute", + 'xpath': '//button[contains(text(), "Easy Apply") or contains(text(), "Apply now") and contains(@data-job-id, "")]' } ] - while attempt < 2: + while attempt < 3: self.check_for_premium_redirect(job) self._scroll_page() + try: + logger.info("Removing focus from the active element") + self.driver.execute_script("document.activeElement.blur();") + time.sleep(1) + + logger.info("Clicking on body to reset focus via JavaScript") + try: + self.driver.execute_script("document.querySelector('body').focus();") + except Exception as e: + logger.warning(f"Failed to reset focus via body: {e}") + + time.sleep(1) + + logger.info("Clicking on html to reset focus via JavaScript") + try: + self.driver.execute_script("document.querySelector('html').focus();") + except Exception as e: + logger.warning(f"Failed to reset focus via html: {e}") + + except Exception as e: + logger.warning(f"Failed to remove focus from the active element: {e}") + for method in search_methods: try: - logger.debug(f"Attempting search using {method['description']}") + logger.info(f"Attempt {attempt + 1}: Searching for 'Easy Apply' button using {method['description']}") if method.get('find_elements'): - buttons = self.driver.find_elements(By.XPATH, method['xpath']) if buttons: for index, button in enumerate(buttons): try: + WebDriverWait(self.driver, timeout).until(EC.visibility_of(button)) + WebDriverWait(self.driver, timeout).until(EC.element_to_be_clickable(button)) + logger.info(f"Found 'Easy Apply' button {index + 1}, attempting to click") + + self.driver.execute_script("arguments[0].scrollIntoView(true);", button) + time.sleep(1) + if button.is_enabled() and button.is_displayed(): + return button + else: + raise Exception(f"Button {index + 1} is not enabled or not displayed") - WebDriverWait(self.driver, 10).until(EC.visibility_of(button)) - WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(button)) - logger.debug(f"Found 'Easy Apply' button {index + 1}, attempting to click") - return button except Exception as e: logger.warning(f"Button {index + 1} found but not clickable: {e}") else: raise TimeoutException("No 'Easy Apply' buttons found") else: - - button = WebDriverWait(self.driver, 10).until( + button = WebDriverWait(self.driver, timeout).until( EC.presence_of_element_located((By.XPATH, method['xpath'])) ) - WebDriverWait(self.driver, 10).until(EC.visibility_of(button)) - WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(button)) - logger.debug("Found 'Easy Apply' button, attempting to click") - return button + WebDriverWait(self.driver, timeout).until(EC.visibility_of(button)) + WebDriverWait(self.driver, timeout).until(EC.element_to_be_clickable(button)) + logger.info("Found 'Easy Apply' button, attempting to click") + + self.driver.execute_script("arguments[0].scrollIntoView(true);", button) + time.sleep(1) + if button.is_enabled() and button.is_displayed(): + return button + else: + raise Exception("Button is not enabled or not displayed") except TimeoutException: logger.warning(f"Timeout during search using {method['description']}") except Exception as e: - logger.warning( - f"Failed to click 'Easy Apply' button using {method['description']} on attempt {attempt + 1}: {e}") + logger.warning(f"Failed to click 'Easy Apply' button using {method['description']} on attempt {attempt + 1}: {e}") self.check_for_premium_redirect(job) if attempt == 0: - logger.debug("Refreshing page to retry finding 'Easy Apply' button") + logger.info("Refreshing page and clicking on body to retry finding 'Easy Apply' button") self.driver.refresh() time.sleep(random.randint(3, 5)) + + try: + body_element = self.driver.find_element(By.TAG_NAME, 'body') + body_element.click() + logger.info("Clicked on body element to reset the page state") + except Exception as e: + logger.warning(f"Failed to click on body element: {e}") + attempt += 1 - page_source = self.driver.page_source - logger.error("No clickable 'Easy Apply' button found after 2 attempts. Page source:\n%s", page_source) + logger.error("No clickable 'Easy Apply' button found after 2 attempts.") raise Exception("No clickable 'Easy Apply' button found") def _get_job_description(self) -> str: @@ -752,12 +801,24 @@ class LinkedInEasyApplier: if dropdowns: dropdown = dropdowns[0] select = Select(dropdown) - options = [option.text for option in select.options] + options = [option.text for option in select.options if option.text != "Select an option"] logger.debug(f"Dropdown options found: {options}") - question_text = question.find_element(By.TAG_NAME, 'label').text.lower() - logger.debug(f"Processing dropdown or combobox question: {question_text}") + try: + question_text = question.find_element(By.TAG_NAME, 'label').text.lower().strip() + except NoSuchElementException: + logger.warning("Label not found, trying to extract question text from or other elements") + + try: + question_text = question.find_element(By.CSS_SELECTOR, + 'span[aria-hidden="true"]').text.lower().strip() + except NoSuchElementException: + + question_text = section.get_attribute('data-test-text-entity-list-form-title') or "unknown question" + question_text = question_text.lower().strip() + + logger.debug(f"Processing dropdown question: {question_text}") current_selection = select.first_selected_option.text logger.debug(f"Current selection: {current_selection}") @@ -772,14 +833,14 @@ class LinkedInEasyApplier: logger.debug(f"Found existing answer for question '{question_text}': {existing_answer}") if current_selection != existing_answer: logger.debug(f"Updating selection to: {existing_answer}") - self._select_dropdown_option(dropdown, existing_answer) + self._select_dropdown_option(select, existing_answer) return True logger.debug(f"No existing answer found, querying model for: {question_text}") answer = self.gpt_answerer.answer_question_from_options(question_text, options) self._save_questions_to_json({'type': 'dropdown', 'question': question_text, 'answer': answer}) - self._select_dropdown_option(dropdown, answer) + self._select_dropdown_option(select, answer) logger.debug(f"Selected new dropdown answer: {answer}") return True @@ -794,6 +855,15 @@ class LinkedInEasyApplier: logger.warning(f"Failed to handle dropdown or combobox question: {e}", exc_info=True) return False + + def _select_dropdown_option(self, select: Select, text: str) -> None: + + try: + select.select_by_visible_text(text) + logger.debug(f"Selected option: {text}") + except Exception as e: + logger.error(f"Failed to select option '{text}': {e}") + def _is_numeric_field(self, field: WebElement) -> bool: field_type = field.get_attribute('type').lower() field_id = field.get_attribute("id").lower() @@ -814,15 +884,26 @@ class LinkedInEasyApplier: return radios[-1].find_element(By.TAG_NAME, 'label').click() - def _select_dropdown_option(self, element: WebElement, text: str) -> None: - logger.debug("Selecting dropdown option: %s", text) - select = Select(element) - select.select_by_visible_text(text) def _save_questions_to_json(self, question_data: dict) -> None: + """ + Save question data to a JSON file, with filtering to exclude company-specific or unsuitable questions. + + Args: + question_data (dict): The question and answer data to be saved. + """ output_file = 'answers.json' question_data['question'] = self._sanitize_text(question_data['question']) logger.debug("Saving question data to JSON: %s", question_data) + + # List of keywords to exclude certain questions from being saved + exclusion_keywords = ["why us", "summary"] + + # Check if the question contains any exclusion keywords + if any(keyword in question_data['question'].lower() for keyword in exclusion_keywords): + logger.info(f"Skipping saving question due to company-specific keywords: {question_data['question']}") + return # Skip saving this question if it's company-specific + try: try: with open(output_file, 'r') as f: @@ -836,7 +917,9 @@ class LinkedInEasyApplier: except FileNotFoundError: logger.warning("JSON file not found, creating new file") data = [] + data.append(question_data) + with open(output_file, 'w') as f: json.dump(data, f, indent=4) logger.debug("Question data saved successfully to JSON") diff --git a/src/linkedIn_job_manager.py b/src/linkedIn_job_manager.py index 1e1db0a..778be4f 100644 --- a/src/linkedIn_job_manager.py +++ b/src/linkedIn_job_manager.py @@ -72,10 +72,28 @@ class LinkedInJobManager: logger.debug("Setting resume generator manager") self.resume_generator_manager = resume_generator_manager + def wait_or_skip(self, time_left): + """Method for waiting or skipping the sleep time based on user input""" + if time_left > 0: + try: + user_input = inputimeout( + prompt=f"Sleeping for {time_left} seconds. Press 'y' to skip waiting. Timeout 60 seconds : ", + timeout=60).strip().lower() + except TimeoutOccurred: + user_input = '' # No input after timeout + if user_input == 'y': + logger.debug("User chose to skip waiting.") + utils.printyellow("User skipped waiting.") + else: + logger.debug(f"Sleeping for {time_left} seconds as user chose not to skip.") + utils.printyellow(f"Sleeping for {time_left} seconds.") + time.sleep(time_left) + def start_applying(self): logger.debug("Starting job application process") self.easy_applier_component = LinkedInEasyApplier(self.driver, self.resume_path, self.set_old_answers, - self.gpt_answerer, self.resume_generator_manager) + self.gpt_answerer, self.resume_generator_manager, + self.parameters) searches = list(product(self.positions, self.locations)) random.shuffle(searches) page_sleep = 0 @@ -116,39 +134,15 @@ class LinkedInJobManager: time_left = minimum_page_time - time.time() - # Ask user if they want to skip waiting, with timeout - if time_left > 0: - try: - user_input = inputimeout( - prompt=f"Sleeping for {time_left} seconds. Press 'y' to skip waiting. Timeout 60 seconds : ", - timeout=60).strip().lower() - except TimeoutOccurred: - user_input = '' # No input after timeout - if user_input == 'y': - logger.debug("User chose to skip waiting.") - utils.printyellow("User skipped waiting.") - else: - logger.debug(f"Sleeping for {time_left} seconds as user chose not to skip.") - utils.printyellow(f"Sleeping for {time_left} seconds.") - time.sleep(time_left) + # Use the wait_or_skip function for sleeping + self.wait_or_skip(time_left) minimum_page_time = time.time() + minimum_time if page_sleep % 5 == 0: sleep_time = random.randint(5, 34) - try: - user_input = inputimeout( - prompt=f"Sleeping for {sleep_time / 60} minutes. Press 'y' to skip waiting. Timeout 60 seconds : ", - timeout=60).strip().lower() - except TimeoutOccurred: - user_input = '' # No input after timeout - if user_input == 'y': - logger.debug("User chose to skip waiting.") - utils.printyellow("User skipped waiting.") - else: - logger.debug(f"Sleeping for {sleep_time} seconds.") - utils.printyellow(f"Sleeping for {sleep_time / 60} minutes.") - time.sleep(sleep_time) + # Use the wait_or_skip function for extended sleep + self.wait_or_skip(sleep_time) page_sleep += 1 except Exception as e: logger.error("Unexpected error during job search: %s", e) @@ -157,38 +151,15 @@ class LinkedInJobManager: time_left = minimum_page_time - time.time() - if time_left > 0: - try: - user_input = inputimeout( - prompt=f"Sleeping for {time_left} seconds. Press 'y' to skip waiting. Timeout 60 seconds : ", - timeout=60).strip().lower() - except TimeoutOccurred: - user_input = '' # No input after timeout - if user_input == 'y': - logger.debug("User chose to skip waiting.") - utils.printyellow("User skipped waiting.") - else: - logger.debug(f"Sleeping for {time_left} seconds as user chose not to skip.") - utils.printyellow(f"Sleeping for {time_left} seconds.") - time.sleep(time_left) + # Use the wait_or_skip function again before moving to the next search + self.wait_or_skip(time_left) minimum_page_time = time.time() + minimum_time if page_sleep % 5 == 0: sleep_time = random.randint(50, 90) - try: - user_input = inputimeout( - prompt=f"Sleeping for {sleep_time / 60} minutes. Press 'y' to skip waiting: ", - timeout=60).strip().lower() - except TimeoutOccurred: - user_input = '' # No input after timeout - if user_input == 'y': - logger.debug("User chose to skip waiting.") - utils.printyellow("User skipped waiting.") - else: - logger.debug(f"Sleeping for {sleep_time} seconds.") - utils.printyellow(f"Sleeping for {sleep_time / 60} minutes.") - time.sleep(sleep_time) + # Use the wait_or_skip function for a longer sleep period + self.wait_or_skip(sleep_time) page_sleep += 1 def get_jobs_from_page(self): @@ -207,7 +178,7 @@ class LinkedInJobManager: try: job_results = self.driver.find_element(By.CLASS_NAME, "jobs-search-results-list") utils.scroll_slow(self.driver, job_results) - utils.scroll_slow(self.driver, job_results, step=300, reverse=True) + # utils.scroll_slow(self.driver, job_results, step=300, reverse=True) job_list_elements = self.driver.find_elements(By.CLASS_NAME, 'scaffold-layout__list-container')[ 0].find_elements(By.CLASS_NAME, 'jobs-search-results__list-item') @@ -265,23 +236,32 @@ class LinkedInJobManager: # Iterate over each job insight element to find the one containing the word "applicant" for element in job_insight_elements: - logger.debug(f"Checking element text: {element.text}") - if "applicant" in element.text.lower(): - # Found an element containing "applicant" - applicants_text = element.text.strip() - logger.debug(f"Applicants text found: {applicants_text}") + applicants_text = element.text.strip().lower() + logger.debug(f"Checking element text: {applicants_text}") - # Extract numeric digits from the text (e.g., "70 applicants" -> "70") + # Look for keywords indicating the presence of applicants count + if "applicant" in applicants_text: + logger.info(f"Applicants text found: {applicants_text}") + + # Try to find numeric value in the text, such as "27 applicants" or "over 100 applicants" applicants_count = ''.join(filter(str.isdigit, applicants_text)) - logger.debug(f"Extracted applicants count: {applicants_count}") if applicants_count: - if "over" in applicants_text.lower(): - applicants_count = int(applicants_count) + 1 # Handle "over X applicants" - logger.debug(f"Applicants count adjusted for 'over': {applicants_count}") - else: - applicants_count = int(applicants_count) # Convert the extracted number to an integer - break + applicants_count = int(applicants_count) # Convert the extracted number to an integer + logger.info(f"Extracted numeric applicants count: {applicants_count}") + + # Handle case with "over X applicants" + if "over" in applicants_text: + applicants_count += 1 + logger.info(f"Adjusted applicants count for 'over': {applicants_count}") + + logger.info(f"Final applicants count: {applicants_count}") + else: + logger.warning(f"Applicants count could not be extracted from text: {applicants_text}") + + break # Stop after finding the first valid applicants count element + else: + logger.info(f"Skipping element as it does not contain 'applicant': {applicants_text}") # Check if applicants_count is valid (not None) before performing comparisons if applicants_count is not None: @@ -291,13 +271,13 @@ class LinkedInJobManager: f"Skipping {job.title} at {job.company} due to applicants count: {applicants_count}") logger.debug(f"Skipping {job.title} at {job.company}, applicants count: {applicants_count}") self.write_to_file(job, "skipped_due_to_applicants") - continue # Skip this job if applicants count is outside the threshold else: logger.debug(f"Applicants count {applicants_count} is within the threshold") else: # If no applicants count was found, log a warning but continue the process logger.warning( - f"Applicants count not found for {job.title} at {job.company}, continuing with application.") + f"Applicants count not found for {job.title} at {job.company}, but continuing with application.") + except NoSuchElementException: # Log a warning if the job insight elements are not found, but do not stop the job application process logger.warning( @@ -370,7 +350,8 @@ class LinkedInJobManager: url_parts = [] if parameters['remote']: url_parts.append("f_CF=f_WRA") - experience_levels = [str(i + 1) for i, (level, v) in enumerate(parameters.get('experience_level', {}).items()) if + 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)}") diff --git a/src/utils.py b/src/utils.py index 0cd2c87..974787e 100644 --- a/src/utils.py +++ b/src/utils.py @@ -179,3 +179,8 @@ def printyellow(text): reset = "\033[0m" logger.debug("Printing text in yellow: %s", text) print(f"{yellow}{text}{reset}") + + +def stringWidth(text, font, font_size): + bbox = font.getbbox(text) + return bbox[2] - bbox[0] From eae841136fccdbd4b96bb8a1c21e60f35f68e588 Mon Sep 17 00:00:00 2001 From: queukat Date: Fri, 13 Sep 2024 02:33:58 +0300 Subject: [PATCH 10/11] fixed easy apply button, make some refactoring and fixed saiving cover letters --- src/linkedIn_easy_applier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linkedIn_easy_applier.py b/src/linkedIn_easy_applier.py index dd33beb..cd5170e 100644 --- a/src/linkedIn_easy_applier.py +++ b/src/linkedIn_easy_applier.py @@ -24,7 +24,7 @@ from src.utils import logger class LinkedInEasyApplier: def __init__(self, driver: Any, resume_dir: Optional[str], set_old_answers: List[Tuple[str, str, str]], - gpt_answerer: Any, resume_generator_manager, parameters: dict): + gpt_answerer: Any, resume_generator_manager): logger.debug("Initializing LinkedInEasyApplier") if resume_dir is None or not os.path.exists(resume_dir): resume_dir = None From f77706d5793495d0ae393fbff1e2d5ef336cf671 Mon Sep 17 00:00:00 2001 From: tapas-joshi Date: Thu, 12 Sep 2024 21:30:35 -0400 Subject: [PATCH 11/11] Loguru Integration: Better logs --- app_config.py | 1 + main.py | 25 +- requirements.txt | 1 + resume_yaml_generator.py | 15 +- src/job.py | 12 +- src/job_application_profile.py | 62 ++-- src/linkedIn_authenticator.py | 29 +- src/linkedIn_bot_facade.py | 12 +- src/linkedIn_easy_applier.py | 213 ++++------- src/linkedIn_job_manager.py | 183 +++++----- src/linkedin-api.py | 17 +- src/llm/llm_manager.py | 569 +++++++++++++++++++++++++++++ src/utils.py | 82 ++--- tests/test_linkedIn_job_manager.py | 4 +- 14 files changed, 851 insertions(+), 374 deletions(-) create mode 100644 app_config.py create mode 100644 src/llm/llm_manager.py diff --git a/app_config.py b/app_config.py new file mode 100644 index 0000000..75684d1 --- /dev/null +++ b/app_config.py @@ -0,0 +1 @@ +MINIMUM_LOG_LEVEL="DEBUG" \ No newline at end of file diff --git a/main.py b/main.py index 047724b..4457c60 100644 --- a/main.py +++ b/main.py @@ -7,14 +7,15 @@ import click from selenium import webdriver from selenium.webdriver.chrome.service import Service as ChromeService from webdriver_manager.chrome import ChromeDriverManager -from selenium.common.exceptions import WebDriverException, TimeoutException +from selenium.common.exceptions import WebDriverException from lib_resume_builder_AIHawk import Resume,StyleManager,FacadeManager,ResumeGenerator from src.utils import chrome_browser_options -from src.gpt import GPTAnswerer +from src.llm.llm_manager import GPTAnswerer from src.linkedIn_authenticator import LinkedInAuthenticator from src.linkedIn_bot_facade import LinkedInBotFacade from src.linkedIn_job_manager import LinkedInJobManager from src.job_application_profile import JobApplicationProfile +from loguru import logger # Suppress stderr sys.stderr = open(os.devnull, 'w') @@ -181,7 +182,7 @@ def create_and_run_bot(email, password, parameters, llm_api_key): bot.start_login() bot.start_apply() except WebDriverException as e: - print(f"WebDriver error occurred: {e}") + logger.error(f"WebDriver error occurred: {e}") except Exception as e: raise RuntimeError(f"Error running the bot: {str(e)}") @@ -201,20 +202,20 @@ def main(resume: Path = None): create_and_run_bot(email, password, parameters, llm_api_key) except ConfigError as ce: - print(f"Configuration error: {str(ce)}") - print("Refer to the configuration guide for troubleshooting: https://github.com/feder-cr/LinkedIn_AIHawk_automatic_job_application/blob/main/readme.md#configuration") + logger.error(f"Configuration error: {str(ce)}") + logger.error(f"Refer to the configuration guide for troubleshooting: https://github.com/feder-cr/LinkedIn_AIHawk_automatic_job_application/blob/main/readme.md#configuration {str(ce)}") except FileNotFoundError as fnf: - print(f"File not found: {str(fnf)}") - print("Ensure all required files are present in the data folder.") - print("Refer to the file setup guide: https://github.com/feder-cr/LinkedIn_AIHawk_automatic_job_application/blob/main/readme.md#configuration") + logger.error(f"File not found: {str(fnf)}") + logger.error("Ensure all required files are present in the data folder.") + logger.error("Refer to the file setup guide: https://github.com/feder-cr/LinkedIn_AIHawk_automatic_job_application/blob/main/readme.md#configuration") except RuntimeError as re: - print(f"Runtime error: {str(re)}") + logger.error(f"Runtime error: {str(re)}") - print("Refer to the configuration and troubleshooting guide: https://github.com/feder-cr/LinkedIn_AIHawk_automatic_job_application/blob/main/readme.md#configuration") + logger.error("Refer to the configuration and troubleshooting guide: https://github.com/feder-cr/LinkedIn_AIHawk_automatic_job_application/blob/main/readme.md#configuration") except Exception as e: - print(f"An unexpected error occurred: {str(e)}") - print("Refer to the general troubleshooting guide: https://github.com/feder-cr/LinkedIn_AIHawk_automatic_job_application/blob/main/readme.md#configuration") + logger.error(f"An unexpected error occurred: {str(e)}") + logger.error("Refer to the general troubleshooting guide: https://github.com/feder-cr/LinkedIn_AIHawk_automatic_job_application/blob/main/readme.md#configuration") if __name__ == "__main__": main() diff --git a/requirements.txt b/requirements.txt index 70cdb62..e037c54 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,3 +25,4 @@ httpx~=0.27.2 python-dotenv~=1.0.1 PyYAML~=6.0.2 pytest>=8.3.3 +loguru==0.7.2 \ No newline at end of file diff --git a/resume_yaml_generator.py b/resume_yaml_generator.py index 336a23d..fd38d56 100644 --- a/resume_yaml_generator.py +++ b/resume_yaml_generator.py @@ -6,6 +6,7 @@ from typing import Dict, Any import re from jsonschema import validate, ValidationError from pdfminer.high_level import extract_text +from loguru import logger def load_yaml(file_path: str) -> Dict[str, Any]: with open(file_path, 'r') as file: @@ -119,7 +120,7 @@ def generate_report(validation_result: Dict[str, Any], output_file: str): report += "YAML is not valid. Errors:\n" report += validation_result["errors"] + "\n" - print(report) + logger.debug(report) def pdf_to_text(pdf_path: str) -> str: return extract_text(pdf_path) @@ -137,24 +138,24 @@ def main(): # Check if input is PDF or TXT if args.input.lower().endswith('.pdf'): resume_text = pdf_to_text(args.input) - print(f"PDF resume converted to text successfully.") + logger.debug(f"PDF resume converted to text successfully.") else: resume_text = load_resume_text(args.input) generated_yaml = generate_yaml_from_resume(resume_text, schema, api_key) save_yaml(generated_yaml, args.output) - print(f"Resume YAML generated and saved to {args.output}") + logger.debug(f"Resume YAML generated and saved to {args.output}") validation_result = validate_yaml(generated_yaml, schema) if validation_result["valid"]: - print("YAML is valid and conforms to the schema.") + logger.debug("YAML is valid and conforms to the schema.") else: - print("YAML is not valid. Errors:") - print(validation_result["errors"]) + logger.error("YAML is not valid. Errors:") + logger.error(validation_result["errors"]) except Exception as e: - print(f"An error occurred: {e}") + logger.error(f"An error occurred: {e}") if __name__ == "__main__": main() diff --git a/src/job.py b/src/job.py index 39b2371..ff72d47 100644 --- a/src/job.py +++ b/src/job.py @@ -1,6 +1,6 @@ from dataclasses import dataclass -from src.utils import logger +from loguru import logger @dataclass @@ -16,22 +16,22 @@ class Job: recruiter_link: str = "" def set_summarize_job_description(self, summarize_job_description): - logger.debug("Setting summarized job description: %s", summarize_job_description) + logger.debug(f"Setting summarized job description: {summarize_job_description}") self.summarize_job_description = summarize_job_description def set_job_description(self, description): - logger.debug("Setting job description: %s", description) + logger.debug(f"Setting job description: {description}") self.description = description def set_recruiter_link(self, recruiter_link): - logger.debug("Setting recruiter link: %s", recruiter_link) + logger.debug(f"Setting recruiter link: {recruiter_link}") self.recruiter_link = recruiter_link def formatted_job_information(self): """ Formats the job information as a markdown string. """ - logger.debug("Formatting job information for job: %s at %s", self.title, self.company) + logger.debug(f"Formatting job information for job: {self.title} at {self.company}") job_information = f""" # Job Description ## Job Information @@ -44,5 +44,5 @@ class Job: {self.description or 'No description provided.'} """ formatted_information = job_information.strip() - logger.debug("Formatted job information: %s", formatted_information) + logger.debug(f"Formatted job information: {formatted_information}") return formatted_information diff --git a/src/job_application_profile.py b/src/job_application_profile.py index 5330c2b..62385db 100644 --- a/src/job_application_profile.py +++ b/src/job_application_profile.py @@ -2,7 +2,7 @@ from dataclasses import dataclass import yaml -from src.utils import logger +from loguru import logger @dataclass @@ -58,106 +58,106 @@ class JobApplicationProfile: logger.debug("Initializing JobApplicationProfile with provided YAML string") try: data = yaml.safe_load(yaml_str) - logger.debug("YAML data successfully parsed: %s", data) + logger.debug(f"YAML data successfully parsed: {data}") except yaml.YAMLError as e: - logger.error("Error parsing YAML file: %s", e) + logger.error(f"Error parsing YAML file: {e}") raise ValueError("Error parsing YAML file.") from e except Exception as e: - logger.error("Unexpected error occurred while parsing the YAML file: %s", e) + logger.error(f"Unexpected error occurred while parsing the YAML file: {e}") raise RuntimeError("An unexpected error occurred while parsing the YAML file.") from e if not isinstance(data, dict): - logger.error("YAML data must be a dictionary, received: %s", type(data)) + logger.error(f"YAML data must be a dictionary, received: {type(data)}") raise TypeError("YAML data must be a dictionary.") # Process self_identification try: logger.debug("Processing self_identification") self.self_identification = SelfIdentification(**data['self_identification']) - logger.debug("self_identification processed: %s", self.self_identification) + logger.debug(f"self_identification processed: {self.self_identification}") except KeyError as e: - logger.error("Required field %s is missing in self_identification data.", e) + logger.error(f"Required field {e} is missing in self_identification data.") raise KeyError(f"Required field {e} is missing in self_identification data.") from e except TypeError as e: - logger.error("Error in self_identification data: %s", e) + logger.error(f"Error in self_identification data: {e}") raise TypeError(f"Error in self_identification data: {e}") from e except AttributeError as e: - logger.error("Attribute error in self_identification processing: %s", e) + logger.error(f"Attribute error in self_identification processing: {e}") raise AttributeError("Attribute error in self_identification processing.") from e except Exception as e: - logger.error("An unexpected error occurred while processing self_identification: %s", e) + logger.error(f"An unexpected error occurred while processing self_identification: {e}") raise RuntimeError("An unexpected error occurred while processing self_identification.") from e # Process legal_authorization try: logger.debug("Processing legal_authorization") self.legal_authorization = LegalAuthorization(**data['legal_authorization']) - logger.debug("legal_authorization processed: %s", self.legal_authorization) + logger.debug(f"legal_authorization processed: {self.legal_authorization}") except KeyError as e: - logger.error("Required field %s is missing in legal_authorization data.", e) + logger.error(f"Required field {e} is missing in legal_authorization data.") raise KeyError(f"Required field {e} is missing in legal_authorization data.") from e except TypeError as e: - logger.error("Error in legal_authorization data: %s", e) + logger.error(f"Error in legal_authorization data: {e}") raise TypeError(f"Error in legal_authorization data: {e}") from e except AttributeError as e: - logger.error("Attribute error in legal_authorization processing: %s", e) + logger.error(f"Attribute error in legal_authorization processing: {e}") raise AttributeError("Attribute error in legal_authorization processing.") from e except Exception as e: - logger.error("An unexpected error occurred while processing legal_authorization: %s", e) + logger.error(f"An unexpected error occurred while processing legal_authorization: {e}") raise RuntimeError("An unexpected error occurred while processing legal_authorization.") from e # Process work_preferences try: logger.debug("Processing work_preferences") self.work_preferences = WorkPreferences(**data['work_preferences']) - logger.debug("work_preferences processed: %s", self.work_preferences) + logger.debug(f"Work_preferences processed: {self.work_preferences}") except KeyError as e: - logger.error("Required field %s is missing in work_preferences data.", e) + logger.error(f"Required field {e} is missing in work_preferences data.") raise KeyError(f"Required field {e} is missing in work_preferences data.") from e except TypeError as e: - logger.error("Error in work_preferences data: %s", e) + logger.error(f"Error in work_preferences data: {e}") raise TypeError(f"Error in work_preferences data: {e}") from e except AttributeError as e: - logger.error("Attribute error in work_preferences processing: %s", e) + logger.error(f"Attribute error in work_preferences processing: {e}") raise AttributeError("Attribute error in work_preferences processing.") from e except Exception as e: - logger.error("An unexpected error occurred while processing work_preferences: %s", e) + logger.error(f"An unexpected error occurred while processing work_preferences: {e}") raise RuntimeError("An unexpected error occurred while processing work_preferences.") from e # Process availability try: logger.debug("Processing availability") self.availability = Availability(**data['availability']) - logger.debug("availability processed: %s", self.availability) + logger.debug(f"Availability processed: {self.availability}") except KeyError as e: - logger.error("Required field %s is missing in availability data.", e) + logger.error(f"Required field {e} is missing in availability data.") raise KeyError(f"Required field {e} is missing in availability data.") from e except TypeError as e: - logger.error("Error in availability data: %s", e) + logger.error(f"Error in availability data: {e}") raise TypeError(f"Error in availability data: {e}") from e except AttributeError as e: - logger.error("Attribute error in availability processing: %s", e) + logger.error(f"Attribute error in availability processing: {e}") raise AttributeError("Attribute error in availability processing.") from e except Exception as e: - logger.error("An unexpected error occurred while processing availability: %s", e) + logger.error(f"An unexpected error occurred while processing availability: {e}") raise RuntimeError("An unexpected error occurred while processing availability.") from e # Process salary_expectations try: logger.debug("Processing salary_expectations") self.salary_expectations = SalaryExpectations(**data['salary_expectations']) - logger.debug("salary_expectations processed: %s", self.salary_expectations) + logger.debug(f"salary_expectations processed: {self.salary_expectations}") except KeyError as e: - logger.error("Required field %s is missing in salary_expectations data.", e) + logger.error(f"Required field {e} is missing in salary_expectations data.") raise KeyError(f"Required field {e} is missing in salary_expectations data.") from e except TypeError as e: - logger.error("Error in salary_expectations data: %s", e) + logger.error(f"Error in salary_expectations data: {e}") raise TypeError(f"Error in salary_expectations data: {e}") from e except AttributeError as e: - logger.error("Attribute error in salary_expectations processing: %s", e) + logger.error(f"Attribute error in salary_expectations processing: {e}") raise AttributeError("Attribute error in salary_expectations processing.") from e except Exception as e: - logger.error("An unexpected error occurred while processing salary_expectations: %s", e) + logger.error(f"An unexpected error occurred while processing salary_expectations: {e}") raise RuntimeError("An unexpected error occurred while processing salary_expectations.") from e logger.debug("JobApplicationProfile initialization completed successfully.") @@ -173,5 +173,5 @@ class JobApplicationProfile: f"Work Preferences:\n{format_dataclass(self.work_preferences)}\n\n" f"Availability: {self.availability.notice_period}\n\n" f"Salary Expectations: {self.salary_expectations.salary_range_usd}\n\n") - logger.debug("String representation generated: %s", formatted_str) + logger.debug(f"String representation generated: {formatted_str}") return formatted_str diff --git a/src/linkedIn_authenticator.py b/src/linkedIn_authenticator.py index 6c49dfc..9030314 100644 --- a/src/linkedIn_authenticator.py +++ b/src/linkedIn_authenticator.py @@ -6,7 +6,7 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait -from src.utils import logger +from loguru import logger class LinkedInAuthenticator: @@ -15,12 +15,12 @@ class LinkedInAuthenticator: self.driver = driver self.email = "" self.password = "" - logger.debug("LinkedInAuthenticator initialized with driver: %s", driver) + logger.debug(f"LinkedInAuthenticator initialized with driver: {driver}") def set_secrets(self, email, password): self.email = email self.password = password - logger.debug("Secrets set with email: %s", email) + logger.debug(f"Secrets set with email: {email}") def start(self): logger.info("Starting Chrome browser to log in to LinkedIn.") @@ -40,13 +40,13 @@ class LinkedInAuthenticator: logger.info("Navigating to the LinkedIn login page...") self.driver.get("https://www.linkedin.com/login") if 'feed' in self.driver.current_url: - print("User is already logged in.") + logger.debug("User is already logged in.") return try: self.enter_credentials() self.submit_login_form() except NoSuchElementException as e: - logger.error("Could not log in to LinkedIn. Element not found: %s", e) + logger.error(f"Could not log in to LinkedIn. Element not found: {e}") time.sleep(random.uniform(3, 5)) self.handle_security_check() @@ -57,13 +57,13 @@ class LinkedInAuthenticator: EC.presence_of_element_located((By.ID, "username")) ) email_field.send_keys(self.email) - logger.debug("Email entered: %s", self.email) + logger.debug(f"Email entered: {self.email}") password_field = self.driver.find_element(By.ID, "password") password_field.send_keys(self.password) logger.debug("Password entered.") except TimeoutException: logger.error("Login form not found. Aborting login.") - print("Login form not found. Aborting login.") + logger.error("Login form not found. Aborting login.") def submit_login_form(self): try: @@ -73,7 +73,6 @@ class LinkedInAuthenticator: logger.debug("Login form submitted.") except NoSuchElementException: logger.error("Login button not found. Please verify the page structure.") - print("Login button not found. Please verify the page structure.") def handle_security_check(self): try: @@ -82,22 +81,19 @@ class LinkedInAuthenticator: EC.url_contains('https://www.linkedin.com/checkpoint/challengesV2/') ) logger.warning("Security checkpoint detected. Please complete the challenge.") - print("Security checkpoint detected. Please complete the challenge.") WebDriverWait(self.driver, 300).until( EC.url_contains('https://www.linkedin.com/feed/') ) logger.info("Security check completed") - print("Security check completed") except TimeoutException: - logger.error("Security check not completed within the timeout.") - print("Security check not completed. Please try again later.") + logger.error("Security check not completed. Please try again later.") def is_logged_in(self): # target_url = 'https://www.linkedin.com/feed' # # # Navigate to the target URL if not already there # if self.driver.current_url != target_url: - # logger.debug("Navigating to target URL: %s", target_url) + # logger.debug(f"Navigating to target URL: {target_url}") # self.driver.get(target_url) try: @@ -109,10 +105,10 @@ class LinkedInAuthenticator: # Check for the presence of the "Start a post" button buttons = self.driver.find_elements(By.CLASS_NAME, 'share-box-feed-entry__trigger') - logger.debug("Found %d 'Start a post' buttons", len(buttons)) + logger.debug(f"Found {len(buttons)} 'Start a post' buttons") for i, button in enumerate(buttons): - logger.debug("Button %d text: %s", i + 1, button.text.strip()) + logger.debug(f"Button {i + 1} text: {button.text.strip()}") if any(button.text.strip().lower() == 'start a post' for button in buttons): logger.info("Found 'Start a post' button indicating user is logged in.") @@ -132,11 +128,10 @@ class LinkedInAuthenticator: def wait_for_page_load(self, timeout=10): try: - logger.debug("Waiting for page to load with timeout: %s seconds", timeout) + logger.debug(f"Waiting for page to load with timeout: {timeout} seconds") WebDriverWait(self.driver, timeout).until( lambda d: d.execute_script('return document.readyState') == 'complete' ) logger.debug("Page load completed.") except TimeoutException: logger.error("Page load timed out.") - print("Page load timed out.") diff --git a/src/linkedIn_bot_facade.py b/src/linkedIn_bot_facade.py index 2f1732c..b910ec4 100644 --- a/src/linkedIn_bot_facade.py +++ b/src/linkedIn_bot_facade.py @@ -1,4 +1,4 @@ -from src.utils import logger +from loguru import logger class LinkedInBotState: @@ -16,10 +16,10 @@ class LinkedInBotState: self.logged_in = False def validate_state(self, required_keys): - logger.debug("Validating LinkedInBotState with required keys: %s", required_keys) + logger.debug(f"Validating LinkedInBotState with required keys: {required_keys}") for key in required_keys: if not getattr(self, key): - logger.error("State validation failed: %s is not set", key) + logger.error(f"State validation failed: {key} is not set") raise ValueError(f"{key.replace('_', ' ').capitalize()} must be set before proceeding.") logger.debug("State validation passed") @@ -87,11 +87,11 @@ class LinkedInBotFacade: logger.debug("Apply process started successfully") def _validate_non_empty(self, value, name): - logger.debug("Validating that %s is not empty", name) + logger.debug(f"Validating that {name} is not empty") if not value: - logger.error("Validation failed: %s is empty", name) + logger.error(f"Validation failed: {name} is empty") raise ValueError(f"{name} cannot be empty.") - logger.debug("Validation passed for %s", name) + logger.debug(f"Validation passed for {name}") def _ensure_job_profile_and_resume_set(self): logger.debug("Ensuring job profile and resume are set") diff --git a/src/linkedIn_easy_applier.py b/src/linkedIn_easy_applier.py index cd5170e..82c60fc 100644 --- a/src/linkedIn_easy_applier.py +++ b/src/linkedIn_easy_applier.py @@ -19,7 +19,7 @@ from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import Select, WebDriverWait import src.utils as utils -from src.utils import logger +from loguru import logger class LinkedInEasyApplier: @@ -39,7 +39,7 @@ class LinkedInEasyApplier: def _load_questions_from_json(self) -> List[dict]: output_file = 'answers.json' - logger.debug("Loading questions from JSON file: %s", output_file) + logger.debug(f"Loading questions from JSON file: {output_file}") try: with open(output_file, 'r') as f: try: @@ -56,7 +56,7 @@ class LinkedInEasyApplier: return [] except Exception: tb_str = traceback.format_exc() - logger.error("Error loading questions data from JSON file: %s", tb_str) + logger.error(f"Error loading questions data from JSON file: {tb_str}") raise Exception(f"Error loading questions data from JSON file: \nTraceback:\n{tb_str}") def check_for_premium_redirect(self, job: Any, max_attempts=3): @@ -73,7 +73,7 @@ class LinkedInEasyApplier: current_url = self.driver.current_url if "linkedin.com/premium" in current_url: - logger.error("Failed to return to job page after %d attempts. Cannot apply for the job.", max_attempts) + logger.error(f"Failed to return to job page after {max_attempts} attempts. Cannot apply for the job.") raise Exception( f"Redirected to LinkedIn Premium page and failed to return after {max_attempts} attempts. Job application aborted.") @@ -92,13 +92,13 @@ class LinkedInEasyApplier: raise e def job_apply(self, job: Any): - logger.debug("Starting job application for job: %s", job) + logger.debug(f"Starting job application for job: {job}") try: self.driver.get(job.link) - logger.debug("Navigated to job link: %s", job.link) + logger.debug(f"Navigated to job link: {job.link}") except Exception as e: - logger.error("Failed to navigate to job link: %s, error: %s", job.link, str(e)) + logger.error(f"Failed to navigate to job link: {job.link}, error: {str(e)}") raise time.sleep(random.uniform(3, 5)) @@ -118,39 +118,29 @@ class LinkedInEasyApplier: logger.debug("Retrieving job description") job_description = self._get_job_description() job.set_job_description(job_description) - logger.debug("Job description set: %s", job_description[:100]) + logger.debug(f"Job description set: {job_description[:100]}") logger.debug("Retrieving recruiter link") recruiter_link = self._get_job_recruiter() job.set_recruiter_link(recruiter_link) - logger.debug("Recruiter link set: %s", recruiter_link) + logger.debug(f"Recruiter link set: {recruiter_link}") - # Try clicking the "Easy Apply" button - try: - logger.debug("Attempting to click 'Easy Apply' button using ActionChains") - actions = ActionChains(self.driver) - actions.move_to_element(easy_apply_button).click().perform() - logger.debug("'Easy Apply' button clicked successfully") - except Exception as e: - logger.warning(f"Failed to click 'Easy Apply' button using ActionChains: {e}, trying JavaScript click") - try: - self.driver.execute_script("arguments[0].click();", easy_apply_button) - logger.debug("'Easy Apply' button clicked successfully via JavaScript") - except Exception as js_error: - logger.error(f"Failed to click 'Easy Apply' button via JavaScript: {js_error}") - raise + logger.debug("Attempting to click 'Easy Apply' button") + actions = ActionChains(self.driver) + actions.move_to_element(easy_apply_button).click().perform() + logger.debug("'Easy Apply' button clicked successfully") logger.debug("Passing job information to GPT Answerer") self.gpt_answerer.set_job(job) logger.debug("Filling out application form") self._fill_application_form(job) - logger.debug("Job application process completed successfully for job: %s", job) + logger.debug(f"Job application process completed successfully for job: {job}") except Exception as e: tb_str = traceback.format_exc() - logger.error("Failed to apply to job: %s. Error traceback: %s", job, tb_str) + logger.error(f"Failed to apply to job: {job}, error: {tb_str}") logger.debug("Discarding application due to failure") self._discard_application() @@ -160,112 +150,73 @@ class LinkedInEasyApplier: def _find_easy_apply_button(self, job: Any) -> WebElement: logger.debug("Searching for 'Easy Apply' button") attempt = 0 - timeout = 8 search_methods = [ - { - 'description': "'aria-label' containing 'Easy Apply to' and with data-job-id attribute", - 'xpath': '//button[contains(@aria-label, "Easy Apply to") and contains(@data-job-id, "")]' - }, { 'description': "find all 'Easy Apply' buttons using find_elements", 'find_elements': True, - 'xpath': '//button[contains(@class, "jobs-apply-button") and contains(., "Easy Apply") and contains(@data-job-id, "")]' + 'xpath': '//button[contains(@class, "jobs-apply-button") and contains(., "Easy Apply")]' }, { - 'description': "button text search with data-job-id attribute", - 'xpath': '//button[contains(text(), "Easy Apply") or contains(text(), "Apply now") and contains(@data-job-id, "")]' + 'description': "'aria-label' containing 'Easy Apply to'", + 'xpath': '//button[contains(@aria-label, "Easy Apply to")]' + }, + { + 'description': "button text search", + 'xpath': '//button[contains(text(), "Easy Apply") or contains(text(), "Apply now")]' } ] - while attempt < 3: + while attempt < 2: self.check_for_premium_redirect(job) self._scroll_page() - try: - logger.info("Removing focus from the active element") - self.driver.execute_script("document.activeElement.blur();") - time.sleep(1) - - logger.info("Clicking on body to reset focus via JavaScript") - try: - self.driver.execute_script("document.querySelector('body').focus();") - except Exception as e: - logger.warning(f"Failed to reset focus via body: {e}") - - time.sleep(1) - - logger.info("Clicking on html to reset focus via JavaScript") - try: - self.driver.execute_script("document.querySelector('html').focus();") - except Exception as e: - logger.warning(f"Failed to reset focus via html: {e}") - - except Exception as e: - logger.warning(f"Failed to remove focus from the active element: {e}") - for method in search_methods: try: - logger.info(f"Attempt {attempt + 1}: Searching for 'Easy Apply' button using {method['description']}") + logger.debug(f"Attempting search using {method['description']}") if method.get('find_elements'): + buttons = self.driver.find_elements(By.XPATH, method['xpath']) if buttons: for index, button in enumerate(buttons): try: - WebDriverWait(self.driver, timeout).until(EC.visibility_of(button)) - WebDriverWait(self.driver, timeout).until(EC.element_to_be_clickable(button)) - logger.info(f"Found 'Easy Apply' button {index + 1}, attempting to click") - - self.driver.execute_script("arguments[0].scrollIntoView(true);", button) - time.sleep(1) - if button.is_enabled() and button.is_displayed(): - return button - else: - raise Exception(f"Button {index + 1} is not enabled or not displayed") + WebDriverWait(self.driver, 10).until(EC.visibility_of(button)) + WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(button)) + logger.debug(f"Found 'Easy Apply' button {index + 1}, attempting to click") + return button except Exception as e: logger.warning(f"Button {index + 1} found but not clickable: {e}") else: raise TimeoutException("No 'Easy Apply' buttons found") else: - button = WebDriverWait(self.driver, timeout).until( + + button = WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.XPATH, method['xpath'])) ) - WebDriverWait(self.driver, timeout).until(EC.visibility_of(button)) - WebDriverWait(self.driver, timeout).until(EC.element_to_be_clickable(button)) - logger.info("Found 'Easy Apply' button, attempting to click") - - self.driver.execute_script("arguments[0].scrollIntoView(true);", button) - time.sleep(1) - if button.is_enabled() and button.is_displayed(): - return button - else: - raise Exception("Button is not enabled or not displayed") + WebDriverWait(self.driver, 10).until(EC.visibility_of(button)) + WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(button)) + logger.debug("Found 'Easy Apply' button, attempting to click") + return button except TimeoutException: logger.warning(f"Timeout during search using {method['description']}") except Exception as e: - logger.warning(f"Failed to click 'Easy Apply' button using {method['description']} on attempt {attempt + 1}: {e}") + logger.warning( + f"Failed to click 'Easy Apply' button using {method['description']} on attempt {attempt + 1}: {e}") self.check_for_premium_redirect(job) if attempt == 0: - logger.info("Refreshing page and clicking on body to retry finding 'Easy Apply' button") + logger.debug("Refreshing page to retry finding 'Easy Apply' button") self.driver.refresh() time.sleep(random.randint(3, 5)) - - try: - body_element = self.driver.find_element(By.TAG_NAME, 'body') - body_element.click() - logger.info("Clicked on body element to reset the page state") - except Exception as e: - logger.warning(f"Failed to click on body element: {e}") - attempt += 1 - logger.error("No clickable 'Easy Apply' button found after 2 attempts.") + page_source = self.driver.page_source + logger.error(f"No clickable 'Easy Apply' button found after 2 attempts. Page source:\n{page_source}") raise Exception("No clickable 'Easy Apply' button found") def _get_job_description(self) -> str: @@ -285,11 +236,11 @@ class LinkedInEasyApplier: return description except NoSuchElementException: tb_str = traceback.format_exc() - logger.error("Job description not found: %s", tb_str) + logger.error(f"Job description not found: {tb_str}") raise Exception(f"Job description not found: \nTraceback:\n{tb_str}") except Exception: tb_str = traceback.format_exc() - logger.error("Error getting Job description: %s", tb_str) + logger.error(f"Error getting Job description: {tb_str}") raise Exception(f"Error getting Job description: \nTraceback:\n{tb_str}") def _get_job_recruiter(self): @@ -306,13 +257,13 @@ class LinkedInEasyApplier: if recruiter_elements: recruiter_element = recruiter_elements[0] recruiter_link = recruiter_element.get_attribute('href') - logger.debug("Job recruiter link retrieved successfully: %s", recruiter_link) + logger.debug(f"Job recruiter link retrieved successfully: {recruiter_link}") return recruiter_link else: logger.debug("No recruiter link found in the hiring team section") return "" except Exception as e: - logger.warning("Failed to retrieve recruiter information: %s", e) + logger.warning(f"Failed to retrieve recruiter information: {e}") return "" def _scroll_page(self) -> None: @@ -322,7 +273,7 @@ class LinkedInEasyApplier: utils.scroll_slow(self.driver, scrollable_element, step=300, reverse=True) def _fill_application_form(self, job): - logger.debug("Filling out application form for job: %s", job) + logger.debug(f"Filling out application form for job: {job}") while True: self.fill_up(job) if self._next_or_submit(): @@ -352,13 +303,13 @@ class LinkedInEasyApplier: By.XPATH, "//label[contains(.,'to stay up to date with their page.')]") follow_checkbox.click() except Exception as e: - logger.warning("Failed to unfollow company: %s", e) + logger.debug(f"Failed to unfollow company: {e}") def _check_for_errors(self) -> None: logger.debug("Checking for form errors") error_elements = self.driver.find_elements(By.CLASS_NAME, 'artdeco-inline-feedback--error') if error_elements: - logger.error("Form submission failed with errors: %s", [e.text for e in error_elements]) + logger.error(f"Form submission failed with errors: {error_elements}") raise Exception(f"Failed answering or file upload. {str([e.text for e in error_elements])}") def _discard_application(self) -> None: @@ -369,10 +320,10 @@ class LinkedInEasyApplier: self.driver.find_elements(By.CLASS_NAME, 'artdeco-modal__confirm-dialog-btn')[0].click() time.sleep(random.uniform(3, 5)) except Exception as e: - logger.warning("Failed to discard application: %s", e) + logger.warning(f"Failed to discard application: {e}") def fill_up(self, job) -> None: - logger.debug("Filling up form sections for job: %s", job) + logger.debug(f"Filling up form sections for job: {job}") try: easy_apply_content = WebDriverWait(self.driver, 10).until( @@ -435,7 +386,7 @@ class LinkedInEasyApplier: def _is_upload_field(self, element: WebElement) -> bool: is_upload = bool(element.find_elements(By.XPATH, ".//input[@type='file']")) - logger.debug("Element is upload field: %s", is_upload) + logger.debug(f"Element is upload field: {is_upload}") return is_upload def _handle_upload_fields(self, element: WebElement, job) -> None: @@ -801,24 +752,12 @@ class LinkedInEasyApplier: if dropdowns: dropdown = dropdowns[0] select = Select(dropdown) - options = [option.text for option in select.options if option.text != "Select an option"] + options = [option.text for option in select.options] logger.debug(f"Dropdown options found: {options}") - try: - question_text = question.find_element(By.TAG_NAME, 'label').text.lower().strip() - except NoSuchElementException: - logger.warning("Label not found, trying to extract question text from or other elements") - - try: - question_text = question.find_element(By.CSS_SELECTOR, - 'span[aria-hidden="true"]').text.lower().strip() - except NoSuchElementException: - - question_text = section.get_attribute('data-test-text-entity-list-form-title') or "unknown question" - question_text = question_text.lower().strip() - - logger.debug(f"Processing dropdown question: {question_text}") + question_text = question.find_element(By.TAG_NAME, 'label').text.lower() + logger.debug(f"Processing dropdown or combobox question: {question_text}") current_selection = select.first_selected_option.text logger.debug(f"Current selection: {current_selection}") @@ -833,14 +772,14 @@ class LinkedInEasyApplier: logger.debug(f"Found existing answer for question '{question_text}': {existing_answer}") if current_selection != existing_answer: logger.debug(f"Updating selection to: {existing_answer}") - self._select_dropdown_option(select, existing_answer) + self._select_dropdown_option(dropdown, existing_answer) return True logger.debug(f"No existing answer found, querying model for: {question_text}") answer = self.gpt_answerer.answer_question_from_options(question_text, options) self._save_questions_to_json({'type': 'dropdown', 'question': question_text, 'answer': answer}) - self._select_dropdown_option(select, answer) + self._select_dropdown_option(dropdown, answer) logger.debug(f"Selected new dropdown answer: {answer}") return True @@ -855,55 +794,35 @@ class LinkedInEasyApplier: logger.warning(f"Failed to handle dropdown or combobox question: {e}", exc_info=True) return False - - def _select_dropdown_option(self, select: Select, text: str) -> None: - - try: - select.select_by_visible_text(text) - logger.debug(f"Selected option: {text}") - except Exception as e: - logger.error(f"Failed to select option '{text}': {e}") - def _is_numeric_field(self, field: WebElement) -> bool: field_type = field.get_attribute('type').lower() field_id = field.get_attribute("id").lower() is_numeric = 'numeric' in field_id or field_type == 'number' or ('text' == field_type and 'numeric' in field_id) - logger.debug("Field type: %s, Field ID: %s, Is numeric: %s", field_type, field_id, is_numeric) + logger.debug(f"Field type: {field_type}, Field ID: {field_id}, Is numeric: {is_numeric}") return is_numeric def _enter_text(self, element: WebElement, text: str) -> None: - logger.debug("Entering text: %s", text) + logger.debug(f"Entering text: {text}") element.clear() element.send_keys(text) def _select_radio(self, radios: List[WebElement], answer: str) -> None: - logger.debug("Selecting radio option: %s", answer) + logger.debug(f"Selecting radio option: {answer}") for radio in radios: if answer in radio.text.lower(): radio.find_element(By.TAG_NAME, 'label').click() return radios[-1].find_element(By.TAG_NAME, 'label').click() + def _select_dropdown_option(self, element: WebElement, text: str) -> None: + logger.debug(f"Selecting dropdown option: {text}") + select = Select(element) + select.select_by_visible_text(text) def _save_questions_to_json(self, question_data: dict) -> None: - """ - Save question data to a JSON file, with filtering to exclude company-specific or unsuitable questions. - - Args: - question_data (dict): The question and answer data to be saved. - """ output_file = 'answers.json' question_data['question'] = self._sanitize_text(question_data['question']) - logger.debug("Saving question data to JSON: %s", question_data) - - # List of keywords to exclude certain questions from being saved - exclusion_keywords = ["why us", "summary"] - - # Check if the question contains any exclusion keywords - if any(keyword in question_data['question'].lower() for keyword in exclusion_keywords): - logger.info(f"Skipping saving question due to company-specific keywords: {question_data['question']}") - return # Skip saving this question if it's company-specific - + logger.debug(f"Saving question data to JSON: {question_data}") try: try: with open(output_file, 'r') as f: @@ -917,19 +836,17 @@ class LinkedInEasyApplier: except FileNotFoundError: logger.warning("JSON file not found, creating new file") data = [] - data.append(question_data) - with open(output_file, 'w') as f: json.dump(data, f, indent=4) logger.debug("Question data saved successfully to JSON") except Exception: tb_str = traceback.format_exc() - logger.error("Error saving questions data to JSON file: %s", tb_str) + logger.error(f"Error saving questions data to JSON file: {tb_str}") raise Exception(f"Error saving questions data to JSON file: \nTraceback:\n{tb_str}") def _sanitize_text(self, text: str) -> str: sanitized_text = text.lower().strip().replace('"', '').replace('\\', '') sanitized_text = re.sub(r'[\x00-\x1F\x7F]', '', sanitized_text).replace('\n', ' ').replace('\r', '').rstrip(',') - logger.debug("Sanitized text: %s", sanitized_text) + logger.debug(f"Sanitized text: {sanitized_text}") return sanitized_text diff --git a/src/linkedIn_job_manager.py b/src/linkedIn_job_manager.py index 778be4f..b608c07 100644 --- a/src/linkedIn_job_manager.py +++ b/src/linkedIn_job_manager.py @@ -12,7 +12,7 @@ from selenium.webdriver.common.by import By import src.utils as utils from src.job import Job from src.linkedIn_easy_applier import LinkedInEasyApplier -from src.utils import logger +from loguru import logger class EnvironmentKeys: @@ -20,19 +20,18 @@ class EnvironmentKeys: logger.debug("Initializing EnvironmentKeys") self.skip_apply = self._read_env_key_bool("SKIP_APPLY") self.disable_description_filter = self._read_env_key_bool("DISABLE_DESCRIPTION_FILTER") - logger.debug("EnvironmentKeys initialized: skip_apply=%s, disable_description_filter=%s", - self.skip_apply, self.disable_description_filter) + logger.debug(f"EnvironmentKeys initialized: skip_apply={self.skip_apply}, disable_description_filter={self.disable_description_filter}") @staticmethod def _read_env_key(key: str) -> str: value = os.getenv(key, "") - logger.debug("Read environment key %s: %s", key, value) + logger.debug(f"Read environment key {key}: {value}") return value @staticmethod def _read_env_key_bool(key: str) -> bool: value = os.getenv(key) == "True" - logger.debug("Read environment key %s as bool: %s", key, value) + logger.debug(f"Read environment key {key} as bool: {value}") return value @@ -72,28 +71,10 @@ class LinkedInJobManager: logger.debug("Setting resume generator manager") self.resume_generator_manager = resume_generator_manager - def wait_or_skip(self, time_left): - """Method for waiting or skipping the sleep time based on user input""" - if time_left > 0: - try: - user_input = inputimeout( - prompt=f"Sleeping for {time_left} seconds. Press 'y' to skip waiting. Timeout 60 seconds : ", - timeout=60).strip().lower() - except TimeoutOccurred: - user_input = '' # No input after timeout - if user_input == 'y': - logger.debug("User chose to skip waiting.") - utils.printyellow("User skipped waiting.") - else: - logger.debug(f"Sleeping for {time_left} seconds as user chose not to skip.") - utils.printyellow(f"Sleeping for {time_left} seconds.") - time.sleep(time_left) - def start_applying(self): logger.debug("Starting job application process") self.easy_applier_component = LinkedInEasyApplier(self.driver, self.resume_path, self.set_old_answers, - self.gpt_answerer, self.resume_generator_manager, - self.parameters) + self.gpt_answerer, self.resume_generator_manager) searches = list(product(self.positions, self.locations)) random.shuffle(searches) page_sleep = 0 @@ -103,21 +84,21 @@ class LinkedInJobManager: for position, location in searches: location_url = "&location=" + location job_page_number = -1 - utils.printyellow(f"Starting the search for {position} in {location}.") + logger.debug(f"Starting the search for {position} in {location}.") try: while True: page_sleep += 1 job_page_number += 1 - utils.printyellow(f"Going to job page {job_page_number}") + logger.debug(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)) - utils.printyellow("Starting the application process for this page...") + logger.debug("Starting the application process for this page...") try: jobs = self.get_jobs_from_page() if not jobs: - utils.printyellow("No more jobs found on this page. Exiting loop.") + logger.debug("No more jobs found on this page. Exiting loop.") break except Exception as e: logger.error(f"Failed to retrieve jobs: {e}") @@ -126,40 +107,77 @@ class LinkedInJobManager: try: self.apply_jobs() except Exception as e: - logger.error("Error during job application: %s", e) - utils.printred(f"Error during job application: {e}") + logger.error(f"Error during job application: {e}") continue - utils.printyellow("Applying to jobs on this page has been completed!") + logger.debug("Applying to jobs on this page has been completed!") time_left = minimum_page_time - time.time() - # Use the wait_or_skip function for sleeping - self.wait_or_skip(time_left) + # Ask user if they want to skip waiting, with timeout + if time_left > 0: + try: + user_input = inputimeout( + prompt=f"Sleeping for {time_left} seconds. Press 'y' to skip waiting. Timeout 60 seconds : ", + timeout=60).strip().lower() + except TimeoutOccurred: + user_input = '' # No input after timeout + if user_input == 'y': + logger.debug("User chose to skip waiting.") + else: + logger.debug(f"Sleeping for {time_left} seconds as user chose not to skip.") + time.sleep(time_left) minimum_page_time = time.time() + minimum_time if page_sleep % 5 == 0: sleep_time = random.randint(5, 34) - # Use the wait_or_skip function for extended sleep - self.wait_or_skip(sleep_time) + try: + user_input = inputimeout( + prompt=f"Sleeping for {sleep_time / 60} minutes. Press 'y' to skip waiting. Timeout 60 seconds : ", + timeout=60).strip().lower() + except TimeoutOccurred: + user_input = '' # No input after timeout + if user_input == 'y': + logger.debug("User chose to skip waiting.") + else: + logger.debug(f"Sleeping for {sleep_time} seconds.") + time.sleep(sleep_time) page_sleep += 1 except Exception as e: - logger.error("Unexpected error during job search: %s", e) - utils.printred(f"Unexpected error: {e}") + logger.error(f"Unexpected error during job search: {e}") continue time_left = minimum_page_time - time.time() - # Use the wait_or_skip function again before moving to the next search - self.wait_or_skip(time_left) + if time_left > 0: + try: + user_input = inputimeout( + prompt=f"Sleeping for {time_left} seconds. Press 'y' to skip waiting. Timeout 60 seconds : ", + timeout=60).strip().lower() + except TimeoutOccurred: + user_input = '' # No input after timeout + if user_input == 'y': + logger.debug("User chose to skip waiting.") + else: + logger.debug(f"Sleeping for {time_left} seconds as user chose not to skip.") + time.sleep(time_left) minimum_page_time = time.time() + minimum_time if page_sleep % 5 == 0: sleep_time = random.randint(50, 90) - # Use the wait_or_skip function for a longer sleep period - self.wait_or_skip(sleep_time) + try: + user_input = inputimeout( + prompt=f"Sleeping for {sleep_time / 60} minutes. Press 'y' to skip waiting: ", + timeout=60).strip().lower() + except TimeoutOccurred: + user_input = '' # No input after timeout + if user_input == 'y': + logger.debug("User chose to skip waiting.") + else: + logger.debug(f"Sleeping for {sleep_time} seconds.") + time.sleep(sleep_time) page_sleep += 1 def get_jobs_from_page(self): @@ -168,7 +186,6 @@ class LinkedInJobManager: no_jobs_element = self.driver.find_element(By.CLASS_NAME, 'jobs-search-two-pane__no-results-banner--expand') if 'No matching jobs found' in no_jobs_element.text or 'unfortunately, things aren' in self.driver.page_source.lower(): - utils.printyellow("No matching jobs found on this page.") logger.debug("No matching jobs found on this page, skipping.") return [] @@ -178,12 +195,11 @@ class LinkedInJobManager: try: job_results = self.driver.find_element(By.CLASS_NAME, "jobs-search-results-list") utils.scroll_slow(self.driver, job_results) - # utils.scroll_slow(self.driver, job_results, step=300, reverse=True) + utils.scroll_slow(self.driver, job_results, step=300, reverse=True) job_list_elements = self.driver.find_elements(By.CLASS_NAME, 'scaffold-layout__list-container')[ 0].find_elements(By.CLASS_NAME, 'jobs-search-results__list-item') if not job_list_elements: - utils.printyellow("No job class elements found on page.") logger.debug("No job class elements found on page, skipping.") return [] @@ -201,7 +217,6 @@ class LinkedInJobManager: try: no_jobs_element = self.driver.find_element(By.CLASS_NAME, 'jobs-search-two-pane__no-results-banner--expand') if 'No matching jobs found' in no_jobs_element.text or 'unfortunately, things aren' in self.driver.page_source.lower(): - utils.printyellow("No matching jobs found on this page, moving to next.") logger.debug("No matching jobs found on this page, skipping") return except NoSuchElementException: @@ -215,7 +230,6 @@ class LinkedInJobManager: 0].find_elements(By.CLASS_NAME, 'jobs-search-results__list-item') if not job_list_elements: - utils.printyellow("No job class elements found on page, moving to next page.") logger.debug("No job class elements found on page, skipping") return @@ -236,48 +250,37 @@ class LinkedInJobManager: # Iterate over each job insight element to find the one containing the word "applicant" for element in job_insight_elements: - applicants_text = element.text.strip().lower() - logger.debug(f"Checking element text: {applicants_text}") + logger.debug(f"Checking element text: {element.text}") + if "applicant" in element.text.lower(): + # Found an element containing "applicant" + applicants_text = element.text.strip() + logger.debug(f"Applicants text found: {applicants_text}") - # Look for keywords indicating the presence of applicants count - if "applicant" in applicants_text: - logger.info(f"Applicants text found: {applicants_text}") - - # Try to find numeric value in the text, such as "27 applicants" or "over 100 applicants" + # Extract numeric digits from the text (e.g., "70 applicants" -> "70") applicants_count = ''.join(filter(str.isdigit, applicants_text)) + logger.debug(f"Extracted applicants count: {applicants_count}") if applicants_count: - applicants_count = int(applicants_count) # Convert the extracted number to an integer - logger.info(f"Extracted numeric applicants count: {applicants_count}") - - # Handle case with "over X applicants" - if "over" in applicants_text: - applicants_count += 1 - logger.info(f"Adjusted applicants count for 'over': {applicants_count}") - - logger.info(f"Final applicants count: {applicants_count}") - else: - logger.warning(f"Applicants count could not be extracted from text: {applicants_text}") - - break # Stop after finding the first valid applicants count element - else: - logger.info(f"Skipping element as it does not contain 'applicant': {applicants_text}") + if "over" in applicants_text.lower(): + applicants_count = int(applicants_count) + 1 # Handle "over X applicants" + logger.debug(f"Applicants count adjusted for 'over': {applicants_count}") + else: + applicants_count = int(applicants_count) # Convert the extracted number to an integer + break # Check if applicants_count is valid (not None) before performing comparisons if applicants_count is not None: # Perform the threshold check for applicants count if applicants_count < self.min_applicants or applicants_count > self.max_applicants: - utils.printyellow( - f"Skipping {job.title} at {job.company} due to applicants count: {applicants_count}") logger.debug(f"Skipping {job.title} at {job.company}, applicants count: {applicants_count}") self.write_to_file(job, "skipped_due_to_applicants") + continue # Skip this job if applicants count is outside the threshold else: logger.debug(f"Applicants count {applicants_count} is within the threshold") else: # If no applicants count was found, log a warning but continue the process logger.warning( - f"Applicants count not found for {job.title} at {job.company}, but continuing with application.") - + f"Applicants count not found for {job.title} at {job.company}, continuing with application.") except NoSuchElementException: # Log a warning if the job insight elements are not found, but do not stop the job application process logger.warning( @@ -294,8 +297,7 @@ class LinkedInJobManager: logger.debug(f"Continuing with job application for {job.title} at {job.company}") if self.is_blacklisted(job.title, job.company, job.link): - utils.printyellow(f"Blacklisted {job.title} at {job.company}, skipping...") - logger.debug("Job blacklisted: %s at %s", job.title, job.company) + logger.debug(f"Job blacklisted: {job.title} at {job.company}") self.write_to_file(job, "skipped") continue if self.is_already_applied_to_job(job.title, job.company, job.link): @@ -308,15 +310,14 @@ class LinkedInJobManager: if job.apply_method not in {"Continue", "Applied", "Apply"}: self.easy_applier_component.job_apply(job) self.write_to_file(job, "success") - logger.debug("Applied to job: %s at %s", job.title, job.company) + logger.debug(f"Applied to job: {job.title} at {job.company}") except Exception as e: - logger.error("Failed to apply for %s at %s: %s", job.title, job.company, e) - utils.printred(f"Failed to apply for {job.title} at {job.company}: {e}") + logger.error(f"Failed to apply for {job.title} at {job.company}: {e}") self.write_to_file(job, "failed") continue def write_to_file(self, job, file_name): - logger.debug("Writing job application result to file: %s", file_name) + logger.debug(f"Writing job application result to file: {file_name}") pdf_path = Path(job.pdf_path).resolve() pdf_path = pdf_path.as_uri() data = { @@ -331,27 +332,26 @@ class LinkedInJobManager: if not file_path.exists(): with open(file_path, 'w', encoding='utf-8') as f: json.dump([data], f, indent=4) - logger.debug("Job data written to new file: %s", file_path) + logger.debug(f"Job data written to new file: {file_name}") else: with open(file_path, 'r+', encoding='utf-8') as f: try: existing_data = json.load(f) except json.JSONDecodeError: - logger.error("JSON decode error in file: %s", file_path) + logger.error(f"JSON decode error in file: {file_path}") existing_data = [] existing_data.append(data) f.seek(0) json.dump(existing_data, f, indent=4) f.truncate() - logger.debug("Job data appended to existing file: %s", file_path) + logger.debug(f"Job data appended to existing file: {file_name}") def get_base_search_url(self, parameters): logger.debug("Constructing base search URL") url_parts = [] if parameters['remote']: url_parts.append("f_CF=f_WRA") - experience_levels = [str(i + 1) for i, (level, v) in enumerate(parameters.get('experience_level', {}).items()) - if + 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)}") @@ -369,11 +369,11 @@ class LinkedInJobManager: url_parts.append("f_LF=f_AL") # Easy Apply base_url = "&".join(url_parts) full_url = f"?{base_url}{date_param}" - logger.debug("Base search URL constructed: %s", full_url) + logger.debug(f"Base search URL constructed: {full_url}") return full_url def next_job_page(self, position, location, job_page): - logger.debug("Navigating to next job page: %s in %s, page %d", position, location, job_page) + logger.debug(f"Navigating to next job page: {position} in {location}, page {job_page}") self.driver.get( f"https://www.linkedin.com/jobs/search/{self.base_search_url}&keywords={position}{location}&start={job_page * 25}") @@ -384,39 +384,36 @@ class LinkedInJobManager: job_title = job_tile.find_element(By.CLASS_NAME, 'job-card-list__title').text link = job_tile.find_element(By.CLASS_NAME, 'job-card-list__title').get_attribute('href').split('?')[0] company = job_tile.find_element(By.CLASS_NAME, 'job-card-container__primary-description').text - logger.debug("Job information extracted: %s at %s", job_title, company) + logger.debug(f"Job information extracted: {job_title} at {company}") except NoSuchElementException: - utils.printyellow("Some job information (title, link, or company) is missing.") logger.warning("Some job information (title, link, or company) is missing.") try: job_location = job_tile.find_element(By.CLASS_NAME, 'job-card-container__metadata-item').text except NoSuchElementException: - utils.printyellow("Job location is missing.") logger.warning("Job location is missing.") try: apply_method = job_tile.find_element(By.CLASS_NAME, 'job-card-container__apply-method').text except NoSuchElementException: apply_method = "Applied" - utils.printyellow("Apply method not found, assuming 'Applied'.") logger.warning("Apply method not found, assuming 'Applied'.") return job_title, company, job_location, link, apply_method def is_blacklisted(self, job_title, company, link): - logger.debug("Checking if job is blacklisted: %s at %s", job_title, company) + logger.debug(f"Checking if job is blacklisted: {job_title} at {company}") job_title_words = job_title.lower().split(' ') title_blacklisted = any(word in job_title_words for word in self.title_blacklist) company_blacklisted = company.strip().lower() in (word.strip().lower() for word in self.company_blacklist) link_seen = link in self.seen_jobs is_blacklisted = title_blacklisted or company_blacklisted or link_seen - logger.debug("Job blacklisted status: %s", is_blacklisted) + logger.debug(f"Job blacklisted status: {is_blacklisted}") return title_blacklisted or company_blacklisted or link_seen def is_already_applied_to_job(self, job_title, company, link): link_seen = link in self.seen_jobs if link_seen: - utils.printyellow(f"Already applied to job: {job_title} at {company}, skipping...") + logger.debug(f"Already applied to job: {job_title} at {company}, skipping...") return link_seen def is_already_applied_to_company(self, company): @@ -432,7 +429,7 @@ class LinkedInJobManager: existing_data = json.load(f) for applied_job in existing_data: if applied_job['company'].strip().lower() == company.strip().lower(): - utils.printyellow( + logger.debug( f"Already applied at {company} (once per company policy), skipping...") return True except json.JSONDecodeError: diff --git a/src/linkedin-api.py b/src/linkedin-api.py index cb38de7..716b3db 100644 --- a/src/linkedin-api.py +++ b/src/linkedin-api.py @@ -2,11 +2,12 @@ from typing import Dict, List from linkedin_api import Linkedin from typing import Optional, Union, Literal from urllib.parse import quote, urlencode, parse_qs, urlparse -import logging +# import logging import json +from loguru import logger # set log to all debug -logging.basicConfig(level=logging.INFO) +# logging.basicConfig(level=logging.INFO) class LinkedInEvolvedAPI(Linkedin): already_applied_jobs: List[str] = [] @@ -388,7 +389,7 @@ class LinkedInEvolvedAPI(Linkedin): case 200: parse_res = res.json() url = parse_res['data']['value'] - logging.info(url) + logger.info(url) return url case _: self.logger.error("Failed to create a request PDF") @@ -496,22 +497,22 @@ if __name__ == "__main__": resume: str = api.upload_linkedin_resume("resume.pdf") if isinstance(resume, bool): - logging.error("Failed to upload resume") + logger.error("Failed to upload resume") continue elif isinstance(resume, str): - logging.info(f"Resume uploaded with hash {resume}") + logger.info(f"Resume uploaded with hash {resume}") else: - logging.error("Unknown error") + logger.error("Unknown error") continue if job_id in api.already_applied_jobs: - logging.info(f"Already applied to job {job_id}, skipping it") + logger.info(f"Already applied to job {job_id}, skipping it") continue fields = api.get_fields_for_easy_apply(job_id) for field in fields: - print(field) + logger.info(field) break diff --git a/src/llm/llm_manager.py b/src/llm/llm_manager.py new file mode 100644 index 0000000..d1f6fe1 --- /dev/null +++ b/src/llm/llm_manager.py @@ -0,0 +1,569 @@ +import json +import os +import re +import textwrap +import time +from abc import ABC, abstractmethod +from datetime import datetime +from pathlib import Path +from typing import Dict, List +from typing import Union + +import httpx +from Levenshtein import distance +from dotenv import load_dotenv +from langchain_core.messages.ai import AIMessage +from langchain_core.output_parsers import StrOutputParser +from langchain_core.prompt_values import StringPromptValue +from langchain_core.prompts import ChatPromptTemplate + +import src.strings as strings +from loguru import logger + +load_dotenv() + + +class AIModel(ABC): + @abstractmethod + def invoke(self, prompt: str) -> str: + pass + + +class OpenAIModel(AIModel): + def __init__(self, api_key: str, llm_model: str, llm_api_url: str): + from langchain_openai import ChatOpenAI + self.model = ChatOpenAI(model_name=llm_model, openai_api_key=api_key, + temperature=0.4, base_url=llm_api_url) + + def invoke(self, prompt: str) -> str: + logger.debug("Invoking OpenAI API") + response = self.model.invoke(prompt) + return response + + +class ClaudeModel(AIModel): + def __init__(self, api_key: str, llm_model: str, llm_api_url: str): + from langchain_anthropic import ChatAnthropic + self.model = ChatAnthropic(model=llm_model, api_key=api_key, + temperature=0.4, base_url=llm_api_url) + + def invoke(self, prompt: str) -> str: + response = self.model.invoke(prompt) + return response + + +class OllamaModel(AIModel): + def __init__(self, api_key: str, llm_model: str, llm_api_url: str): + from langchain_ollama import ChatOllama + self.model = ChatOllama(model=llm_model, base_url=llm_api_url) + + def invoke(self, prompt: str) -> str: + response = self.model.invoke(prompt) + return response + + +class GeminiModel(AIModel): + def __init__(self, api_key:str, llm_model: str, llm_api_url: str): + from langchain_google_genai import ChatGoogleGenerativeAI + self.model = ChatGoogleGenerativeAI(model=llm_model, google_api_key=api_key) + + def invoke(self, prompt: str) -> str: + response = self.model.invoke(prompt) + return response + + +class AIAdapter: + def __init__(self, config: dict, api_key: str): + self.model = self._create_model(config, api_key) + + def _create_model(self, config: dict, api_key: str) -> AIModel: + llm_model_type = config['llm_model_type'] + llm_model = config['llm_model'] + llm_api_url = config['llm_api_url'] + logger.debug('Using {0} with {1} from {2}'.format( + llm_model_type, llm_model, llm_api_url)) + + if llm_model_type == "openai": + return OpenAIModel(api_key, llm_model, llm_api_url) + elif llm_model_type == "claude": + return ClaudeModel(api_key, llm_model, llm_api_url) + elif llm_model_type == "ollama": + return OllamaModel(api_key, llm_model, llm_api_url) + elif llm_model_type == "gemini": + return GeminiModel(api_key, llm_model, llm_api_url) + else: + raise ValueError(f"Unsupported model type: {llm_model_type}") + + def invoke(self, prompt: str) -> str: + return self.model.invoke(prompt) + + +class LLMLogger: + + def __init__(self, llm: Union[OpenAIModel, OllamaModel, ClaudeModel, GeminiModel]): + self.llm = llm + logger.debug(f"LLMLogger successfully initialized with LLM: {llm}") + + @staticmethod + def log_request(prompts, parsed_reply: Dict[str, Dict]): + logger.debug("Starting log_request method") + logger.debug(f"Prompts received: {prompts}") + logger.debug(f"Parsed reply received: {parsed_reply}") + + try: + calls_log = os.path.join( + Path("data_folder/output"), "open_ai_calls.json") + logger.debug(f"Logging path determined: {calls_log}") + except Exception as e: + logger.error(f"Error determining the log path: {str(e)}") + raise + + if isinstance(prompts, StringPromptValue): + logger.debug("Prompts are of type StringPromptValue") + prompts = prompts.text + logger.debug(f"Prompts converted to text: {prompts}") + elif isinstance(prompts, Dict): + logger.debug("Prompts are of type Dict") + try: + prompts = { + f"prompt_{i + 1}": prompt.content + for i, prompt in enumerate(prompts.messages) + } + logger.debug(f"Prompts converted to dictionary: {prompts}") + except Exception as e: + logger.error(f"Error converting prompts to dictionary: {str(e)}") + raise + else: + logger.debug("Prompts are of unknown type, attempting default conversion") + try: + prompts = { + f"prompt_{i + 1}": prompt.content + for i, prompt in enumerate(prompts.messages) + } + logger.debug(f"Prompts converted to dictionary using default method: {prompts}") + except Exception as e: + logger.error(f"Error converting prompts using default method: {str(e)}") + raise + + try: + current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + logger.debug(f"Current time obtained: {current_time}") + except Exception as e: + logger.error(f"Error obtaining current time: {str(e)}") + raise + + try: + token_usage = parsed_reply["usage_metadata"] + output_tokens = token_usage["output_tokens"] + input_tokens = token_usage["input_tokens"] + total_tokens = token_usage["total_tokens"] + logger.debug(f"Token usage - Input: {input_tokens}, Output: {output_tokens}, Total: {total_tokens}") + except KeyError as e: + logger.error(f"KeyError in parsed_reply structure: {str(e)}") + raise + + try: + model_name = parsed_reply["response_metadata"]["model_name"] + logger.debug(f"Model name: {model_name}") + except KeyError as e: + logger.error(f"KeyError in response_metadata: {str(e)}") + raise + + try: + prompt_price_per_token = 0.00000015 + completion_price_per_token = 0.0000006 + total_cost = (input_tokens * prompt_price_per_token) + \ + (output_tokens * completion_price_per_token) + logger.debug(f"Total cost calculated: {total_cost}") + except Exception as e: + logger.error(f"Error calculating total cost: {str(e)}") + raise + + try: + log_entry = { + "model": model_name, + "time": current_time, + "prompts": prompts, + "replies": parsed_reply["content"], + "total_tokens": total_tokens, + "input_tokens": input_tokens, + "output_tokens": output_tokens, + "total_cost": total_cost, + } + logger.debug(f"Log entry created: {log_entry}") + except KeyError as e: + logger.error(f"Error creating log entry: missing key {str(e)} in parsed_reply") + raise + + try: + with open(calls_log, "a", encoding="utf-8") as f: + json_string = json.dumps( + log_entry, ensure_ascii=False, indent=4) + f.write(json_string + "\n") + logger.debug(f"Log entry written to file: {calls_log}") + except Exception as e: + logger.error(f"Error writing log entry to file: {str(e)}") + raise + + +class LoggerChatModel: + + def __init__(self, llm: Union[OpenAIModel, OllamaModel, ClaudeModel, GeminiModel]): + self.llm = llm + logger.debug(f"LoggerChatModel successfully initialized with LLM: {llm}") + + def __call__(self, messages: List[Dict[str, str]]) -> str: + logger.debug(f"Entering __call__ method with messages: {messages}") + while True: + try: + logger.debug("Attempting to call the LLM with messages") + + reply = self.llm.invoke(messages) + logger.debug(f"LLM response received: {reply}") + + parsed_reply = self.parse_llmresult(reply) + logger.debug(f"Parsed LLM reply: {parsed_reply}") + + LLMLogger.log_request( + prompts=messages, parsed_reply=parsed_reply) + logger.debug("Request successfully logged") + + return reply + + except httpx.HTTPStatusError as e: + logger.error(f"HTTPStatusError encountered: {str(e)}") + if e.response.status_code == 429: + retry_after = e.response.headers.get('retry-after') + retry_after_ms = e.response.headers.get('retry-after-ms') + + if retry_after: + wait_time = int(retry_after) + logger.warning( + f"Rate limit exceeded. Waiting for {wait_time} seconds before retrying (extracted from 'retry-after' header)...") + time.sleep(wait_time) + elif retry_after_ms: + wait_time = int(retry_after_ms) / 1000.0 + logger.warning( + f"Rate limit exceeded. Waiting for {wait_time} seconds before retrying (extracted from 'retry-after-ms' header)...") + time.sleep(wait_time) + else: + wait_time = 30 + logger.warning( + f"'retry-after' header not found. Waiting for {wait_time} seconds before retrying (default)...") + time.sleep(wait_time) + else: + logger.error(f"HTTP error occurred with status code: {e.response.status_code}, waiting 30 seconds before retrying") + time.sleep(30) + + except Exception as e: + logger.error(f"Unexpected error occurred: {str(e)}") + logger.info( + "Waiting for 30 seconds before retrying due to an unexpected error.") + time.sleep(30) + continue + + def parse_llmresult(self, llmresult: AIMessage) -> Dict[str, Dict]: + logger.debug(f"Parsing LLM result: {llmresult}") + + try: + content = llmresult.content + response_metadata = llmresult.response_metadata + id_ = llmresult.id + usage_metadata = llmresult.usage_metadata + + parsed_result = { + "content": content, + "response_metadata": { + "model_name": response_metadata.get("model_name", ""), + "system_fingerprint": response_metadata.get("system_fingerprint", ""), + "finish_reason": response_metadata.get("finish_reason", ""), + "logprobs": response_metadata.get("logprobs", None), + }, + "id": id_, + "usage_metadata": { + "input_tokens": usage_metadata.get("input_tokens", 0), + "output_tokens": usage_metadata.get("output_tokens", 0), + "total_tokens": usage_metadata.get("total_tokens", 0), + }, + } + + logger.debug(f"Parsed LLM result successfully: {parsed_result}") + return parsed_result + + except KeyError as e: + logger.error( + f"KeyError while parsing LLM result: missing key {str(e)}") + raise + + except Exception as e: + logger.error( + f"Unexpected error while parsing LLM result: {str(e)}") + raise + + +class GPTAnswerer: + + def __init__(self, config, llm_api_key): + self.ai_adapter = AIAdapter(config, llm_api_key) + self.llm_cheap = LoggerChatModel(self.ai_adapter) + + @property + def job_description(self): + return self.job.description + + @staticmethod + def find_best_match(text: str, options: list[str]) -> str: + logger.debug(f"Finding best match for text: '{text}' in options: {options}") + distances = [ + (option, distance(text.lower(), option.lower())) for option in options + ] + best_option = min(distances, key=lambda x: x[1])[0] + logger.debug(f"Best match found: {best_option}") + return best_option + + @staticmethod + def _remove_placeholders(text: str) -> str: + logger.debug(f"Removing placeholders from text: {text}") + text = text.replace("PLACEHOLDER", "") + return text.strip() + + @staticmethod + def _preprocess_template_string(template: str) -> str: + logger.debug("Preprocessing template string") + return textwrap.dedent(template) + + def set_resume(self, resume): + logger.debug(f"Setting resume: {resume}") + self.resume = resume + + def set_job(self, job): + logger.debug(f"Setting job: {job}") + self.job = job + self.job.set_summarize_job_description( + self.summarize_job_description(self.job.description)) + + def set_job_application_profile(self, job_application_profile): + logger.debug(f"Setting job application profile: {job_application_profile}") + self.job_application_profile = job_application_profile + + def summarize_job_description(self, text: str) -> str: + logger.debug(f"Summarizing job description: {text}") + strings.summarize_prompt_template = self._preprocess_template_string( + strings.summarize_prompt_template + ) + prompt = ChatPromptTemplate.from_template( + strings.summarize_prompt_template) + chain = prompt | self.llm_cheap | StrOutputParser() + output = chain.invoke({"text": text}) + logger.debug(f"Summary generated: {output}") + return output + + def _create_chain(self, template: str): + logger.debug(f"Creating chain with template: {template}") + prompt = ChatPromptTemplate.from_template(template) + return prompt | self.llm_cheap | StrOutputParser() + + def answer_question_textual_wide_range(self, question: str) -> str: + logger.debug(f"Answering textual question: {question}") + chains = { + "personal_information": self._create_chain(strings.personal_information_template), + "self_identification": self._create_chain(strings.self_identification_template), + "legal_authorization": self._create_chain(strings.legal_authorization_template), + "work_preferences": self._create_chain(strings.work_preferences_template), + "education_details": self._create_chain(strings.education_details_template), + "experience_details": self._create_chain(strings.experience_details_template), + "projects": self._create_chain(strings.projects_template), + "availability": self._create_chain(strings.availability_template), + "salary_expectations": self._create_chain(strings.salary_expectations_template), + "certifications": self._create_chain(strings.certifications_template), + "languages": self._create_chain(strings.languages_template), + "interests": self._create_chain(strings.interests_template), + "cover_letter": self._create_chain(strings.coverletter_template), + } + section_prompt = """ + You are assisting a bot designed to automatically apply for jobs on LinkedIn. The bot receives various questions about job applications and needs to determine the most relevant section of the resume to provide an accurate response. + + For the following question: '{question}', determine which section of the resume is most relevant. + Respond with exactly one of the following options: + - Personal information + - Self Identification + - Legal Authorization + - Work Preferences + - Education Details + - Experience Details + - Projects + - Availability + - Salary Expectations + - Certifications + - Languages + - Interests + - Cover letter + + Here are detailed guidelines to help you choose the correct section: + + 1. **Personal Information**: + - **Purpose**: Contains your basic contact details and online profiles. + - **Use When**: The question is about how to contact you or requests links to your professional online presence. + - **Examples**: Email address, phone number, LinkedIn profile, GitHub repository, personal website. + + 2. **Self Identification**: + - **Purpose**: Covers personal identifiers and demographic information. + - **Use When**: The question pertains to your gender, pronouns, veteran status, disability status, or ethnicity. + - **Examples**: Gender, pronouns, veteran status, disability status, ethnicity. + + 3. **Legal Authorization**: + - **Purpose**: Details your work authorization status and visa requirements. + - **Use When**: The question asks about your ability to work in specific countries or if you need sponsorship or visas. + - **Examples**: Work authorization in EU and US, visa requirements, legally allowed to work. + + 4. **Work Preferences**: + - **Purpose**: Specifies your preferences regarding work conditions and job roles. + - **Use When**: The question is about your preferences for remote work, in-person work, relocation, and willingness to undergo assessments or background checks. + - **Examples**: Remote work, in-person work, open to relocation, willingness to complete assessments. + + 5. **Education Details**: + - **Purpose**: Contains information about your academic qualifications. + - **Use When**: The question concerns your degrees, universities attended, GPA, and relevant coursework. + - **Examples**: Degree, university, GPA, field of study, exams. + + 6. **Experience Details**: + - **Purpose**: Details your professional work history and key responsibilities. + - **Use When**: The question pertains to your job roles, responsibilities, and achievements in previous positions. + - **Examples**: Job positions, company names, key responsibilities, skills acquired. + + 7. **Projects**: + - **Purpose**: Highlights specific projects you have worked on. + - **Use When**: The question asks about particular projects, their descriptions, or links to project repositories. + - **Examples**: Project names, descriptions, links to project repositories. + + 8. **Availability**: + - **Purpose**: Provides information on your availability for new roles. + - **Use When**: The question is about how soon you can start a new job or your notice period. + - **Examples**: Notice period, availability to start. + + 9. **Salary Expectations**: + - **Purpose**: Covers your expected salary range. + - **Use When**: The question pertains to your salary expectations or compensation requirements. + - **Examples**: Desired salary range. + + 10. **Certifications**: + - **Purpose**: Lists your professional certifications or licenses. + - **Use When**: The question involves your certifications or qualifications from recognized organizations. + - **Examples**: Certification names, issuing bodies, dates of validity. + + 11. **Languages**: + - **Purpose**: Describes the languages you can speak and your proficiency levels. + - **Use When**: The question asks about your language skills or proficiency in specific languages. + - **Examples**: Languages spoken, proficiency levels. + + 12. **Interests**: + - **Purpose**: Details your personal or professional interests. + - **Use When**: The question is about your hobbies, interests, or activities outside of work. + - **Examples**: Personal hobbies, professional interests. + + 13. **Cover Letter**: + - **Purpose**: Contains your personalized cover letter or statement. + - **Use When**: The question involves your cover letter or specific written content intended for the job application. + - **Examples**: Cover letter content, personalized statements. + + Provide only the exact name of the section from the list above with no additional text. + """ + prompt = ChatPromptTemplate.from_template(section_prompt) + chain = prompt | self.llm_cheap | StrOutputParser() + output = chain.invoke({"question": question}) + + match = re.search( + r"(Personal information|Self Identification|Legal Authorization|Work Preferences|Education " + r"Details|Experience Details|Projects|Availability|Salary " + r"Expectations|Certifications|Languages|Interests|Cover letter)", + output, re.IGNORECASE) + if not match: + raise ValueError( + "Could not extract section name from the response.") + + section_name = match.group(1).lower().replace(" ", "_") + + if section_name == "cover_letter": + chain = chains.get(section_name) + output = chain.invoke( + {"resume": self.resume, "job_description": self.job_description}) + logger.debug(f"Cover letter generated: {output}") + return output + resume_section = getattr(self.resume, section_name, None) or getattr(self.job_application_profile, section_name, + None) + if resume_section is None: + logger.error( + f"Section '{section_name}' not found in either resume or job_application_profile.") + raise ValueError(f"Section '{section_name}' not found in either resume or job_application_profile.") + chain = chains.get(section_name) + if chain is None: + logger.error(f"Chain not defined for section '{section_name}'") + raise ValueError(f"Chain not defined for section '{section_name}'") + output = chain.invoke( + {"resume_section": resume_section, "question": question}) + logger.debug(f"Question answered: {output}") + return output + + def answer_question_numeric(self, question: str, default_experience: int = 3) -> int: + logger.debug(f"Answering numeric question: {question}") + func_template = self._preprocess_template_string( + strings.numeric_question_template) + prompt = ChatPromptTemplate.from_template(func_template) + chain = prompt | self.llm_cheap | StrOutputParser() + output_str = chain.invoke( + {"resume_educations": self.resume.education_details, "resume_jobs": self.resume.experience_details, + "resume_projects": self.resume.projects, "question": question}) + logger.debug(f"Raw output for numeric question: {output_str}") + try: + output = self.extract_number_from_string(output_str) + logger.debug(f"Extracted number: {output}") + except ValueError: + logger.warning( + f"Failed to extract number, using default experience: {default_experience}") + output = default_experience + return output + + def extract_number_from_string(self, output_str): + logger.debug(f"Extracting number from string: {output_str}") + numbers = re.findall(r"\d+", output_str) + if numbers: + logger.debug(f"Numbers found: {numbers}") + return int(numbers[0]) + else: + logger.error("No numbers found in the string") + raise ValueError("No numbers found in the string") + + def answer_question_from_options(self, question: str, options: list[str]) -> str: + logger.debug(f"Answering question from options: {question}") + func_template = self._preprocess_template_string( + strings.options_template) + prompt = ChatPromptTemplate.from_template(func_template) + chain = prompt | self.llm_cheap | StrOutputParser() + output_str = chain.invoke( + {"resume": self.resume, "question": question, "options": options}) + logger.debug(f"Raw output for options question: {output_str}") + best_option = self.find_best_match(output_str, options) + logger.debug(f"Best option determined: {best_option}") + return best_option + + def resume_or_cover(self, phrase: str) -> str: + logger.debug( + f"Determining if phrase refers to resume or cover letter: {phrase}") + prompt_template = """ + Given the following phrase, respond with only 'resume' if the phrase is about a resume, or 'cover' if it's about a cover letter. + If the phrase contains only one word 'upload', consider it as 'cover'. + If the phrase contains 'upload resume', consider it as 'resume'. + Do not provide any additional information or explanations. + + phrase: {phrase} + """ + prompt = ChatPromptTemplate.from_template(prompt_template) + chain = prompt | self.llm_cheap | StrOutputParser() + response = chain.invoke({"phrase": phrase}) + logger.debug(f"Response for resume_or_cover: {response}") + if "resume" in response: + return "resume" + elif "cover" in response: + return "cover" + else: + return "resume" \ No newline at end of file diff --git a/src/utils.py b/src/utils.py index 974787e..587e7a2 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,41 +1,48 @@ import logging import os import random +import sys import time from selenium import webdriver +from loguru import logger + +from app_config import MINIMUM_LOG_LEVEL log_file = "app_log.log" -logging.basicConfig( - level=logging.INFO, - format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - handlers=[ - logging.FileHandler(log_file, mode='a', encoding='utf-8'), - logging.StreamHandler() - ], - force=True # This will reset the root logger's handlers and apply the new configuration -) +# TODO: REMOVE THE FOLLOWING BLOCK: No need as Loguru handles everything by default +# logging.basicConfig( +# level=logging.INFO, +# format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', +# handlers=[ +# logging.FileHandler(log_file, mode='a', encoding='utf-8'), +# logging.StreamHandler() +# ], +# force=True # This will reset the root logger's handlers and apply the new configuration +# ) -logger = logging.getLogger(__name__) -file_handler = logging.FileHandler(log_file, mode='a', encoding='utf-8') -formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') -file_handler.setFormatter(formatter) -logger.addHandler(file_handler) -logger.setLevel(logging.INFO) + + +if MINIMUM_LOG_LEVEL in ["DEBUG", "TRACE", "INFO", "WARNING", "ERROR", "CRITICAL"]: + logger.remove() + logger.add(sys.stderr, level=MINIMUM_LOG_LEVEL) +else: + logger.warning(f"Invalid log level: {MINIMUM_LOG_LEVEL}. Defaulting to DEBUG.") + logger.remove() + logger.add(sys.stderr, level="DEBUG") chromeProfilePath = os.path.join(os.getcwd(), "chrome_profile", "linkedin_profile") - def ensure_chrome_profile(): - logger.debug("Ensuring Chrome profile exists at path: %s", chromeProfilePath) + logger.debug(f"Ensuring Chrome profile exists at path: {chromeProfilePath}") profile_dir = os.path.dirname(chromeProfilePath) if not os.path.exists(profile_dir): os.makedirs(profile_dir) - logger.debug("Created directory for Chrome profile: %s", profile_dir) + logger.debug(f"Created directory for Chrome profile: {profile_dir}") if not os.path.exists(chromeProfilePath): os.makedirs(chromeProfilePath) - logger.debug("Created Chrome profile directory: %s", chromeProfilePath) + logger.debug(f"Created Chrome profile directory: {chromeProfilePath}") return chromeProfilePath @@ -43,13 +50,12 @@ def is_scrollable(element): scroll_height = element.get_attribute("scrollHeight") client_height = element.get_attribute("clientHeight") scrollable = int(scroll_height) > int(client_height) - logger.debug("Element scrollable check: scrollHeight=%s, clientHeight=%s, scrollable=%s", scroll_height, - client_height, scrollable) + logger.debug(f"Element scrollable check: scrollHeight={scroll_height}, clientHeight={client_height}, scrollable={scrollable}") return scrollable def scroll_slow(driver, scrollable_element, start=0, end=3600, step=300, reverse=False): - logger.debug("Starting slow scroll: start=%d, end=%d, step=%d, reverse=%s", start, end, step, reverse) + logger.debug(f"Starting slow scroll: start={start}, end={end}, step={step}, reverse={reverse}") if reverse: start, end = end, start @@ -61,18 +67,16 @@ def scroll_slow(driver, scrollable_element, start=0, end=3600, step=300, reverse max_scroll_height = int(scrollable_element.get_attribute("scrollHeight")) current_scroll_position = int(scrollable_element.get_attribute("scrollTop")) - logger.debug("Max scroll height of the element: %d", max_scroll_height) - logger.debug("Current scroll position: %d", current_scroll_position) + logger.debug(f"Max scroll height of the element: {max_scroll_height}") + logger.debug(f"Current scroll position: {current_scroll_position}") if reverse: - if current_scroll_position < start: start = current_scroll_position - logger.debug("Adjusted start position for upward scroll: %d", start) + logger.debug(f"Adjusted start position for upward scroll: {start}") else: - if end > max_scroll_height: - logger.warning("End value exceeds the scroll height. Adjusting end to %d", max_scroll_height) + logger.warning(f"End value exceeds the scroll height. Adjusting end to {max_scroll_height}") end = max_scroll_height script_scroll_to = "arguments[0].scrollTop = arguments[1];" @@ -81,12 +85,10 @@ def scroll_slow(driver, scrollable_element, start=0, end=3600, step=300, reverse if scrollable_element.is_displayed(): if not is_scrollable(scrollable_element): logger.warning("The element is not scrollable.") - print("The element is not scrollable.") return if (step > 0 and start >= end) or (step < 0 and start <= end): logger.warning("No scrolling will occur due to incorrect start/end values.") - print("No scrolling will occur due to incorrect start/end values.") return position = start @@ -94,15 +96,14 @@ def scroll_slow(driver, scrollable_element, start=0, end=3600, step=300, reverse while (step > 0 and position < end) or (step < 0 and position > end): if position == previous_position: # Avoid re-scrolling to the same position - logger.debug("Stopping scroll as position hasn't changed: %d", position) + logger.debug(f"Stopping scroll as position hasn't changed: {position}") break try: driver.execute_script(script_scroll_to, scrollable_element, position) - logger.debug("Scrolled to position: %d", position) + logger.debug(f"Scrolled to position: {position}") except Exception as e: - logger.error("Error during scrolling: %s", e) - print(f"Error during scrolling: {e}") + logger.error(f"Error during scrolling: {e}") previous_position = position position += step @@ -114,14 +115,12 @@ def scroll_slow(driver, scrollable_element, start=0, end=3600, step=300, reverse # Ensure the final scroll position is correct driver.execute_script(script_scroll_to, scrollable_element, end) - logger.debug("Scrolled to final position: %d", end) + logger.debug(f"Scrolled to final position: {end}") time.sleep(0.5) else: logger.warning("The element is not visible.") - print("The element is not visible.") except Exception as e: - logger.error("Exception occurred during scrolling: %s", e) - print(f"Exception occurred: {e}") + logger.error(f"Exception occurred during scrolling: {e}") def chrome_browser_options(): @@ -159,7 +158,7 @@ def chrome_browser_options(): profile_dir = os.path.basename(chromeProfilePath) options.add_argument('--user-data-dir=' + initial_path) options.add_argument("--profile-directory=" + profile_dir) - logger.debug("Using Chrome profile directory: %s", chromeProfilePath) + logger.debug(f"Using Chrome profile directory: {chromeProfilePath}") else: options.add_argument("--incognito") logger.debug("Using Chrome in incognito mode") @@ -179,8 +178,3 @@ def printyellow(text): reset = "\033[0m" logger.debug("Printing text in yellow: %s", text) print(f"{yellow}{text}{reset}") - - -def stringWidth(text, font, font_size): - bbox = font.getbbox(text) - return bbox[2] - bbox[0] diff --git a/tests/test_linkedIn_job_manager.py b/tests/test_linkedIn_job_manager.py index 0b4121e..d66449b 100644 --- a/tests/test_linkedIn_job_manager.py +++ b/tests/test_linkedIn_job_manager.py @@ -5,6 +5,7 @@ import os import pytest from src.linkedIn_job_manager import LinkedInJobManager from selenium.common.exceptions import NoSuchElementException +from loguru import logger @pytest.fixture @@ -52,8 +53,7 @@ def test_set_parameters(mocker, job_manager): def next_job_page(self, position, location, job_page): - logger.debug("Navigating to next job page: %s in %s, page %d", - position, location, job_page) + logger.debug(f"Navigating to next job page: {position} in {location}, page {job_page}") self.driver.get( f"https://www.linkedin.com/jobs/search/{self.base_search_url}&keywords={position}&location={location}&start={job_page * 25}")