first commit v2
This commit is contained in:
parent
2dcd7943e8
commit
d8b7e7fda6
18 changed files with 663 additions and 1398 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import csv
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
|
|
@ -10,6 +9,7 @@ from selenium.webdriver.common.by import By
|
|||
import utils
|
||||
from job import Job
|
||||
from linkedIn_easy_applier import LinkedInEasyApplier
|
||||
import json
|
||||
|
||||
|
||||
class EnvironmentKeys:
|
||||
|
|
@ -45,15 +45,15 @@ class LinkedInJobManager:
|
|||
self.resume_dir = None
|
||||
self.output_file_directory = Path(parameters['outputFileDirectory'])
|
||||
self.env_config = EnvironmentKeys()
|
||||
self.old_question()
|
||||
#self.old_question()
|
||||
|
||||
def set_gpt_answerer(self, gpt_answerer):
|
||||
self.gpt_answerer = gpt_answerer
|
||||
|
||||
def old_question(self):
|
||||
"""
|
||||
Load old answers from a CSV file into a dictionary.
|
||||
"""
|
||||
def set_resume_generator_manager(self, resume_generator_manager):
|
||||
self.resume_generator_manager = resume_generator_manager
|
||||
|
||||
""" def old_question(self):
|
||||
self.set_old_answers = {}
|
||||
file_path = 'data_folder/output/old_Questions.csv'
|
||||
if os.path.exists(file_path):
|
||||
|
|
@ -62,13 +62,11 @@ class LinkedInJobManager:
|
|||
for row in csv_reader:
|
||||
if len(row) == 3:
|
||||
answer_type, question_text, answer = row
|
||||
self.set_old_answers[(answer_type.lower(), question_text.lower())] = answer
|
||||
self.set_old_answers[(answer_type.lower(), question_text.lower())] = answer"""
|
||||
|
||||
|
||||
def start_applying(self):
|
||||
self.easy_applier_component = LinkedInEasyApplier(
|
||||
self.driver, self.resume_dir, self.set_old_answers, self.gpt_answerer
|
||||
)
|
||||
self.easy_applier_component = LinkedInEasyApplier(self.driver, self.resume_dir, self.set_old_answers, self.gpt_answerer, self.resume_generator_manager)
|
||||
searches = list(product(self.positions, self.locations))
|
||||
random.shuffle(searches)
|
||||
page_sleep = 0
|
||||
|
|
@ -127,50 +125,50 @@ class LinkedInJobManager:
|
|||
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)
|
||||
|
||||
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:
|
||||
raise Exception("No job class elements found on page")
|
||||
|
||||
job_list = [Job(*self.extract_job_information_from_tile(job_element)) for job_element in job_list_elements]
|
||||
|
||||
job_list = [Job(*self.extract_job_information_from_tile(job_element)) for job_element in job_list_elements]
|
||||
for job in job_list:
|
||||
if self.is_blacklisted(job.title, job.company, job.link):
|
||||
utils.printyellow(f"Blacklisted {job.title} at {job.company}, skipping...")
|
||||
self.write_to_file(job.company, job.location, job.title, job.link, "skipped")
|
||||
self.write_to_file(job, "skipped")
|
||||
continue
|
||||
|
||||
try:
|
||||
if job.apply_method not in {"Continue", "Applied", "Apply"}:
|
||||
self.easy_applier_component.job_apply(job)
|
||||
self.write_to_file(job, "success")
|
||||
except Exception as e:
|
||||
utils.printred(traceback.format_exc())
|
||||
self.write_to_file(job.company, job.location, job.title, job.link, "failed")
|
||||
continue
|
||||
self.write_to_file(job.company, job.location, job.title, job.link, "success")
|
||||
self.write_to_file(job, "failed")
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
traceback.format_exc()
|
||||
raise e
|
||||
|
||||
def write_to_file(self, company, job_title, link, job_location, file_name):
|
||||
to_write = [company, job_title, link, job_location]
|
||||
file_path = self.output_file_directory / f"{file_name}.csv"
|
||||
with open(file_path, 'a', newline='', encoding='utf-8') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(to_write)
|
||||
|
||||
def record_gpt_answer(self, answer_type, question_text, gpt_response):
|
||||
to_write = [answer_type, question_text, gpt_response]
|
||||
file_path = self.output_file_directory / "registered_jobs.csv"
|
||||
try:
|
||||
with open(file_path, 'a', newline='', encoding='utf-8') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(to_write)
|
||||
except Exception as e:
|
||||
utils.printred(f"Error writing registered job: {e}")
|
||||
utils.printred(f"Details: Answer type: {answer_type}, Question: {question_text}")
|
||||
def write_to_file(self, job, file_name):
|
||||
data = {
|
||||
"company": job.company,
|
||||
"job_title": job.title,
|
||||
"link": job.link,
|
||||
"job_location": job.location,
|
||||
"pdf_path": job.pdf_path
|
||||
}
|
||||
file_path = self.output_file_directory / f"{file_name}.json"
|
||||
if not file_path.exists():
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
json.dump([data], f, indent=4)
|
||||
else:
|
||||
with open(file_path, 'r+', encoding='utf-8') as f:
|
||||
try:
|
||||
existing_data = json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
existing_data = []
|
||||
existing_data.append(data)
|
||||
f.seek(0)
|
||||
json.dump(existing_data, f, indent=4)
|
||||
f.truncate()
|
||||
|
||||
def get_base_search_url(self, parameters):
|
||||
url_parts = []
|
||||
|
|
@ -205,12 +203,6 @@ class LinkedInJobManager:
|
|||
company = job_tile.find_element(By.CLASS_NAME, 'job-card-container__primary-description').text
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
hiring_line = job_tile.find_element(By.XPATH, '//span[contains(.,\' is hiring for this\')]')
|
||||
hiring_line_text = hiring_line.text
|
||||
name_terminating_index = hiring_line_text.find(' is hiring for this')
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
job_location = job_tile.find_element(By.CLASS_NAME, 'job-card-container__metadata-item').text
|
||||
except:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue