From 74f9f181504cd2f678aed90b1760ed2a5fcf500e Mon Sep 17 00:00:00 2001 From: feder-cr Date: Fri, 23 Aug 2024 15:11:44 +0100 Subject: [PATCH] cofing problem fixed, i hope :) --- linkedIn_job_manager.py | 2 -- main.py | 24 ++++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/linkedIn_job_manager.py b/linkedIn_job_manager.py index 79dfece..e6f2940 100644 --- a/linkedIn_job_manager.py +++ b/linkedIn_job_manager.py @@ -142,8 +142,6 @@ class LinkedInJobManager: self.write_to_file(job, "failed") continue - - def write_to_file(self, job, file_name): pdf_path = Path(job.pdf_path).resolve() pdf_path = pdf_path.as_uri() diff --git a/main.py b/main.py index 1679bf7..6c32516 100644 --- a/main.py +++ b/main.py @@ -37,10 +37,10 @@ class ConfigValidator: except FileNotFoundError: raise ConfigError(f"File not found: {yaml_path}") - @staticmethod + + def validate_config(config_yaml_path: Path) -> dict: parameters = ConfigValidator.validate_yaml_file(config_yaml_path) - required_keys = { 'remote': bool, 'experienceLevel': dict, @@ -52,10 +52,18 @@ class ConfigValidator: 'companyBlacklist': list, 'titleBlacklist': list } - + for key, expected_type in required_keys.items(): - if key not in parameters or not isinstance(parameters[key], expected_type): - raise ConfigError(f"Missing or invalid key '{key}' in config file {config_yaml_path}") + if key not in parameters: + if key in ['companyBlacklist', 'titleBlacklist']: + parameters[key] = [] + else: + raise ConfigError(f"Missing or invalid key '{key}' in config file {config_yaml_path}") + elif not isinstance(parameters[key], expected_type): + if key in ['companyBlacklist', 'titleBlacklist'] and parameters[key] is None: + parameters[key] = [] + else: + raise ConfigError(f"Invalid type for key '{key}' in config file {config_yaml_path}. Expected {expected_type}.") experience_levels = ['internship', 'entry', 'associate', 'mid-senior level', 'director', 'executive'] for level in experience_levels: @@ -82,11 +90,15 @@ class ConfigValidator: raise ConfigError(f"Invalid distance value in config file {config_yaml_path}. Must be one of: {approved_distances}") for blacklist in ['companyBlacklist', 'titleBlacklist']: - if not all(isinstance(item, str) for item in parameters.get(blacklist, [])): + if not isinstance(parameters.get(blacklist), list): + raise ConfigError(f"'{blacklist}' must be a list in config file {config_yaml_path}") + if parameters[blacklist] is None: parameters[blacklist] = [] return parameters + + @staticmethod def validate_secrets(secrets_yaml_path: Path) -> tuple: secrets = ConfigValidator.validate_yaml_file(secrets_yaml_path)