From 70722b57a9bd13193593b37f53242936d94431cc Mon Sep 17 00:00:00 2001 From: KamalMahanna Date: Fri, 30 Aug 2024 20:56:02 +0530 Subject: [PATCH] fixing #272 folder not found error --- run_first.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/run_first.py b/run_first.py index bebfd19c..ffbd9f4c 100644 --- a/run_first.py +++ b/run_first.py @@ -7,8 +7,19 @@ init_logging_config() -PROCESSED_RESUMES_PATH = "Data/Processed/Resumes" -PROCESSED_JOB_DESCRIPTIONS_PATH = "Data/Processed/JobDescription" +script_dir = os.path.dirname(os.path.abspath(__file__)) +PROCESSED_DATA_PATH = os.path.join(script_dir, "Data", "Processed") +PROCESSED_RESUMES_PATH = os.path.join(PROCESSED_DATA_PATH, "Resumes") +PROCESSED_JOB_DESCRIPTIONS_PATH = os.path.join( + PROCESSED_DATA_PATH, "JobDescription" +) + +# check if processed data directory exists +if not os.path.exists(PROCESSED_DATA_PATH): + os.makedirs(PROCESSED_DATA_PATH) + os.makedirs(PROCESSED_RESUMES_PATH) + os.makedirs(PROCESSED_JOB_DESCRIPTIONS_PATH) + logging.info("Created necessary directories.") def read_json(filename): @@ -39,11 +50,13 @@ def remove_old_files(files_path): file_names = get_filenames_from_dir("Data/Resumes") logging.info("Reading from Data/Resumes is now complete.") -except: +except Exception: # Exit the program if there are no resumes. logging.error("There are no resumes present in the specified folder.") logging.error("Exiting from the program.") - logging.error("Please add resumes in the Data/Resumes folder and try again.") + logging.error( + "Please add resumes in the Data/Resumes folder and try again." + ) exit(1) # Now after getting the file_names parse the resumes into a JSON Format. @@ -61,11 +74,15 @@ def remove_old_files(files_path): file_names = get_filenames_from_dir("Data/JobDescription") logging.info("Reading from Data/JobDescription is now complete.") -except: +except Exception: # Exit the program if there are no resumes. - logging.error("There are no job-description present in the specified folder.") + logging.error( + "There are no job-description present in the specified folder." + ) logging.error("Exiting from the program.") - logging.error("Please add resumes in the Data/JobDescription folder and try again.") + logging.error( + "Please add resumes in the Data/JobDescription folder and try again." + ) exit(1) # Now after getting the file_names parse the resumes into a JSON Format.