From 1c03037315e92417df71d6033deb2c422d203732 Mon Sep 17 00:00:00 2001 From: Sundar M Das <34454614+sundarmd@users.noreply.github.com> Date: Sun, 1 Sep 2024 19:47:40 +0200 Subject: [PATCH] Update main.py original script --- main.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 822f9e3..9685677 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from pathlib import Path import yaml import click from selenium import webdriver -from selenium.webdriver.chrome.service import Service +from selenium.webdriver.chrome.service import Service as ChromeService from webdriver_manager.chrome import ChromeDriverManager from selenium.common.exceptions import WebDriverException, TimeoutException from lib_resume_builder_AIHawk import Resume,StyleManager,FacadeManager,ResumeGenerator @@ -32,8 +32,11 @@ class ConfigValidator: try: with open(yaml_path, 'r') as stream: return yaml.safe_load(stream) - except (yaml.YAMLError, FileNotFoundError) as exc: + except yaml.YAMLError as exc: raise ConfigError(f"Error reading file {yaml_path}: {exc}") + except FileNotFoundError: + raise ConfigError(f"File not found: {yaml_path}") + def validate_config(config_yaml_path: Path) -> dict: parameters = ConfigValidator.validate_yaml_file(config_yaml_path) @@ -150,13 +153,7 @@ class FileManager: def init_browser() -> webdriver.Chrome: try: options = chromeBrowserOptions() - - chrome_driver_path = Path(r"C:\Users\sunda\chromedriver-win64\chromedriver-win64\chromedriver.exe") - - if not chrome_driver_path.exists(): - raise FileNotFoundError(f"ChromeDriver not found at {chrome_driver_path}") - - service = Service(executable_path=str(chrome_driver_path)) + service = ChromeService(ChromeDriverManager().install()) return webdriver.Chrome(service=service, options=options) except Exception as e: raise RuntimeError(f"Failed to initialize browser: {str(e)}") @@ -214,7 +211,9 @@ def main(resume: Path = None): 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") except RuntimeError as re: + print(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") except Exception as e: print(f"An unexpected error occurred: {str(e)}")