dropdown fixed

This commit is contained in:
feder-cr 2024-08-22 18:24:37 +01:00
parent 78d0a8ebca
commit 737d9cf457
4 changed files with 25 additions and 25 deletions

3
gpt.py
View File

@ -267,9 +267,6 @@ class GPTAnswerer:
Provide only the exact name of the section from the list above with no additional text. Provide only the exact name of the section from the list above with no additional text.
""" """
prompt = ChatPromptTemplate.from_template(section_prompt) prompt = ChatPromptTemplate.from_template(section_prompt)
chain = prompt | self.llm_cheap | StrOutputParser() chain = prompt | self.llm_cheap | StrOutputParser()
output = chain.invoke({"question": question}) output = chain.invoke({"question": question})

View File

@ -191,7 +191,9 @@ class LinkedInEasyApplier:
def _fill_additional_questions(self) -> None: def _fill_additional_questions(self) -> None:
form_sections = self.driver.find_elements(By.CLASS_NAME, 'jobs-easy-apply-form-section__grouping') form_sections = self.driver.find_elements(By.CLASS_NAME, 'jobs-easy-apply-form-section__grouping')
for section in form_sections: for section in form_sections:
outer_html = section.get_attribute('outerHTML')
self._process_form_section(section) self._process_form_section(section)
def _process_form_section(self, section: WebElement) -> None: def _process_form_section(self, section: WebElement) -> None:
if self._handle_terms_of_service(section): if self._handle_terms_of_service(section):
@ -243,15 +245,18 @@ class LinkedInEasyApplier:
return False return False
def _find_and_handle_dropdown_question(self, section: WebElement) -> bool: def _find_and_handle_dropdown_question(self, section: WebElement) -> bool:
dropdowns = section.find_elements(By.CLASS_NAME, 'fb-dropdown__select') try:
if dropdowns: question = section.find_element(By.CLASS_NAME, 'jobs-easy-apply-form-element')
dropdown = dropdowns[0] question_text = question.find_element(By.TAG_NAME, 'label').text.lower()
question_text = section.text.lower() dropdown = question.find_element(By.TAG_NAME, 'select')
select = Select(dropdown) if dropdown:
answer = self.gpt_answerer.answer_question_from_options(question_text, [option.text.lower() for option in select.options]) select = Select(dropdown)
self._select_dropdown_option(select, answer) options = [option.text for option in select.options]
return True answer = self.gpt_answerer.answer_question_from_options(question_text, options)
return False self._select_dropdown_option(dropdown, answer)
return True
except Exception:
return False
def _is_numeric_field(self, field: WebElement) -> bool: def _is_numeric_field(self, field: WebElement) -> bool:
field_type = field.get_attribute('type').lower() field_type = field.get_attribute('type').lower()
@ -270,8 +275,6 @@ class LinkedInEasyApplier:
radio.click() radio.click()
break break
def _select_dropdown_option(self, select: Select, answer: str) -> None: def _select_dropdown_option(self, element: WebElement, text: str) -> None:
for option in select.options: select = Select(element)
if option.text.lower() == answer.lower(): select.select_by_visible_text(text)
select.select_by_visible_text(option.text)
break

View File

@ -153,8 +153,8 @@ class LinkedInJobManager:
"pdf_path": job.pdf_path "pdf_path": job.pdf_path
} }
file_path = self.output_file_directory / f"{file_name}.json" file_path = self.output_file_directory / f"{file_name}.json"
file_path = file_path.as_posix()
if not file_path.exists(): if not file_path.exists():
job.pdf_path = file_path.as_posix()
with open(file_path, 'w', encoding='utf-8') as f: with open(file_path, 'w', encoding='utf-8') as f:
json.dump([data], f, indent=4) json.dump([data], f, indent=4)
else: else:

14
main.py
View File

@ -149,6 +149,12 @@ def init_browser() -> webdriver.Chrome:
def create_and_run_bot(email: str, password: str, parameters: dict, openai_api_key: str): def create_and_run_bot(email: str, password: str, parameters: dict, openai_api_key: str):
try: try:
style_manager = StyleManager()
resume_generator = ResumeGenerator()
resume_generator_manager = FacadeManager(openai_api_key, style_manager, resume_generator, resume_object, Path("data_folder/output"))
browser = init_browser() browser = init_browser()
login_component = LinkedInAuthenticator(browser) login_component = LinkedInAuthenticator(browser)
@ -161,13 +167,7 @@ def create_and_run_bot(email: str, password: str, parameters: dict, openai_api_k
resume_object = Resume(plain_text_resume) resume_object = Resume(plain_text_resume)
job_application_profile_object = JobApplicationProfile(plain_text_resume) job_application_profile_object = JobApplicationProfile(plain_text_resume)
style_manager = StyleManager()
resume_generator = ResumeGenerator()
resume_generator_manager = FacadeManager(openai_api_key, style_manager, resume_generator, resume_object, Path("data_folder/output"))
os.system('cls' if os.name == 'nt' else 'clear')
resume_generator_manager.choose_style()
bot = LinkedInBotFacade(login_component, apply_component) bot = LinkedInBotFacade(login_component, apply_component)
bot.set_secrets(email, password) bot.set_secrets(email, password)
bot.set_job_application_profile_and_resume(job_application_profile_object, resume_object) bot.set_job_application_profile_and_resume(job_application_profile_object, resume_object)