now the gooole account used is geneated directly inside the script
This commit is contained in:
parent
f281867537
commit
5deb32ad90
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@ data_folder*
|
|||||||
generated_cv*
|
generated_cv*
|
||||||
resume.html
|
resume.html
|
||||||
.vscode
|
.vscode
|
||||||
|
chrome_profile
|
2
main.py
2
main.py
@ -175,10 +175,8 @@ def create_and_run_bot(email: str, password: str, parameters: dict, openai_api_k
|
|||||||
login_component = LinkedInAuthenticator(browser)
|
login_component = LinkedInAuthenticator(browser)
|
||||||
apply_component = LinkedInJobManager(browser)
|
apply_component = LinkedInJobManager(browser)
|
||||||
gpt_answerer_component = GPTAnswerer(openai_api_key)
|
gpt_answerer_component = GPTAnswerer(openai_api_key)
|
||||||
|
|
||||||
with open(parameters['uploads']['plainTextResume'], "r") as file:
|
with open(parameters['uploads']['plainTextResume'], "r") as file:
|
||||||
plain_text_resume_file = file.read()
|
plain_text_resume_file = file.read()
|
||||||
|
|
||||||
resume_object = Resume(plain_text_resume_file)
|
resume_object = Resume(plain_text_resume_file)
|
||||||
bot = LinkedInBotFacade(login_component, apply_component)
|
bot = LinkedInBotFacade(login_component, apply_component)
|
||||||
bot.set_secrets(email, password)
|
bot.set_secrets(email, password)
|
||||||
|
61
utils.py
61
utils.py
@ -10,10 +10,17 @@ import glob
|
|||||||
from webdriver_manager.chrome import ChromeDriverManager
|
from webdriver_manager.chrome import ChromeDriverManager
|
||||||
|
|
||||||
headless = False
|
headless = False
|
||||||
chromeProfilePath = r"/home/.config/google-chrome/linkedin_profile"
|
chromeProfilePath = os.path.join(os.getcwd(), "chrome_profile", "linkedin_profile")
|
||||||
|
|
||||||
|
def ensure_chrome_profile():
|
||||||
|
profile_dir = os.path.dirname(chromeProfilePath)
|
||||||
|
if not os.path.exists(profile_dir):
|
||||||
|
os.makedirs(profile_dir)
|
||||||
|
if not os.path.exists(chromeProfilePath):
|
||||||
|
os.makedirs(chromeProfilePath)
|
||||||
|
return chromeProfilePath
|
||||||
|
|
||||||
def is_scrollable(element):
|
def is_scrollable(element):
|
||||||
"""Controlla se un elemento è scrollabile."""
|
|
||||||
scroll_height = element.get_attribute("scrollHeight")
|
scroll_height = element.get_attribute("scrollHeight")
|
||||||
client_height = element.get_attribute("clientHeight")
|
client_height = element.get_attribute("clientHeight")
|
||||||
return int(scroll_height) > int(client_height)
|
return int(scroll_height) > int(client_height)
|
||||||
@ -22,13 +29,9 @@ def scroll_slow(driver, scrollable_element, start=0, end=3600, step=100, reverse
|
|||||||
if reverse:
|
if reverse:
|
||||||
start, end = end, start
|
start, end = end, start
|
||||||
step = -step
|
step = -step
|
||||||
|
|
||||||
if step == 0:
|
if step == 0:
|
||||||
raise ValueError("Step cannot be zero.")
|
raise ValueError("Step cannot be zero.")
|
||||||
|
|
||||||
# Script di scrolling che utilizza scrollTop
|
|
||||||
script_scroll_to = "arguments[0].scrollTop = arguments[1];"
|
script_scroll_to = "arguments[0].scrollTop = arguments[1];"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if scrollable_element.is_displayed():
|
if scrollable_element.is_displayed():
|
||||||
if not is_scrollable(scrollable_element):
|
if not is_scrollable(scrollable_element):
|
||||||
@ -55,12 +58,9 @@ def HTML_to_PDF(FilePath):
|
|||||||
# Validate and prepare file paths
|
# Validate and prepare file paths
|
||||||
if not os.path.isfile(FilePath):
|
if not os.path.isfile(FilePath):
|
||||||
raise FileNotFoundError(f"The specified file does not exist: {FilePath}")
|
raise FileNotFoundError(f"The specified file does not exist: {FilePath}")
|
||||||
|
|
||||||
FilePath = f"file:///{os.path.abspath(FilePath).replace(os.sep, '/')}"
|
FilePath = f"file:///{os.path.abspath(FilePath).replace(os.sep, '/')}"
|
||||||
|
|
||||||
# Set up Chrome options
|
# Set up Chrome options
|
||||||
chrome_options = webdriver.ChromeOptions()
|
chrome_options = webdriver.ChromeOptions()
|
||||||
|
|
||||||
# Initialize Chrome driver
|
# Initialize Chrome driver
|
||||||
service = ChromeService(ChromeDriverManager().install())
|
service = ChromeService(ChromeDriverManager().install())
|
||||||
driver = webdriver.Chrome(service=service, options=chrome_options)
|
driver = webdriver.Chrome(service=service, options=chrome_options)
|
||||||
@ -68,29 +68,26 @@ def HTML_to_PDF(FilePath):
|
|||||||
try:
|
try:
|
||||||
# Load the HTML file
|
# Load the HTML file
|
||||||
driver.get(FilePath)
|
driver.get(FilePath)
|
||||||
time.sleep(3) # Adjust the sleep time if necessary
|
time.sleep(3)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
pdf_base64 = driver.execute_cdp_cmd("Page.printToPDF", {
|
pdf_base64 = driver.execute_cdp_cmd("Page.printToPDF", {
|
||||||
"printBackground": True, # Incluir los fondos en el PDF
|
"printBackground": True,
|
||||||
"landscape": False, # Orientación vertical
|
"landscape": False,
|
||||||
"paperWidth": 10, # Ancho en pulgadas (Carta: 8.5)
|
"paperWidth": 10,
|
||||||
"paperHeight": 11, # Alto en pulgadas (Carta: 11)
|
"paperHeight": 11,
|
||||||
"marginTop": 0, # Márgenes en pulgadas
|
"marginTop": 0,
|
||||||
"marginBottom": 0,
|
"marginBottom": 0,
|
||||||
"marginLeft": 0,
|
"marginLeft": 0,
|
||||||
"marginRight": 0,
|
"marginRight": 0,
|
||||||
"displayHeaderFooter": False, # No mostrar encabezado y pie de página
|
"displayHeaderFooter": False,
|
||||||
"preferCSSPageSize": True, # Preferir el tamaño de página definido por CSS
|
"preferCSSPageSize": True,
|
||||||
"generateDocumentOutline": False, # No generar un índice en el PDF
|
"generateDocumentOutline": False,
|
||||||
"generateTaggedPDF": False, # No generar PDF accesible
|
"generateTaggedPDF": False,
|
||||||
"transferMode": "ReturnAsBase64" # Retornar el PDF como base64
|
"transferMode": "ReturnAsBase64"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
# Check if PDF generation was successful
|
|
||||||
if time.time() - start_time > 120:
|
if time.time() - start_time > 120:
|
||||||
raise TimeoutError("PDF generation exceeded the specified timeout limit.")
|
raise TimeoutError("PDF generation exceeded the specified timeout limit.")
|
||||||
# Return the base64-encoded PDF
|
|
||||||
return pdf_base64['data']
|
return pdf_base64['data']
|
||||||
|
|
||||||
except WebDriverException as e:
|
except WebDriverException as e:
|
||||||
@ -108,22 +105,28 @@ def chromeBrowserOptions():
|
|||||||
options.add_argument('--disable-gpu')
|
options.add_argument('--disable-gpu')
|
||||||
options.add_argument('--disable-dev-shm-usage')
|
options.add_argument('--disable-dev-shm-usage')
|
||||||
options.add_argument('--remote-debugging-port=9222')
|
options.add_argument('--remote-debugging-port=9222')
|
||||||
if(headless):
|
if headless:
|
||||||
options.add_argument("--headless")
|
options.add_argument("--headless")
|
||||||
options.add_argument("--start-maximized")
|
options.add_argument("--start-maximized")
|
||||||
options.add_argument("--disable-blink-features")
|
options.add_argument("--disable-blink-features")
|
||||||
options.add_argument("--disable-blink-features=AutomationControlled")
|
options.add_argument("--disable-blink-features=AutomationControlled")
|
||||||
options.add_experimental_option('useAutomationExtension', False)
|
options.add_experimental_option('useAutomationExtension', False)
|
||||||
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
||||||
if(len(chromeProfilePath)>0):
|
|
||||||
initialPath = chromeProfilePath[0:chromeProfilePath.rfind("/")]
|
# Assicurati che la directory del profilo Chrome esista
|
||||||
profileDir = chromeProfilePath[chromeProfilePath.rfind("/")+1:]
|
ensure_chrome_profile()
|
||||||
options.add_argument('--user-data-dir=' +initialPath)
|
|
||||||
options.add_argument("--profile-directory=" +profileDir)
|
if len(chromeProfilePath) > 0:
|
||||||
|
initialPath = os.path.dirname(chromeProfilePath)
|
||||||
|
profileDir = os.path.basename(chromeProfilePath)
|
||||||
|
options.add_argument('--user-data-dir=' + initialPath)
|
||||||
|
options.add_argument("--profile-directory=" + profileDir)
|
||||||
else:
|
else:
|
||||||
options.add_argument("--incognito")
|
options.add_argument("--incognito")
|
||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
def printred(text):
|
def printred(text):
|
||||||
# Codice colore ANSI per il rosso
|
# Codice colore ANSI per il rosso
|
||||||
RED = "\033[91m"
|
RED = "\033[91m"
|
||||||
|
Loading…
Reference in New Issue
Block a user