From da719018fd00674b60def5ee1e790e782b908945 Mon Sep 17 00:00:00 2001 From: "Dawn M. Foster" Date: Fri, 1 Dec 2023 13:36:14 +0000 Subject: [PATCH] separated the code to create a new function with the org level directory so that I can use that separately to create the path for a csv file that summarizes the org level details --- utils/file_operations.py | 41 ++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/utils/file_operations.py b/utils/file_operations.py index 5ff5c97..f47ab61 100644 --- a/utils/file_operations.py +++ b/utils/file_operations.py @@ -4,9 +4,38 @@ """ This file contains several functions that perform various file operations """ -def output_path(repo_name, org_name): +def create_path_str(org_name): """ Creates the path string where files will be located + Parameters + ---------- + org_name : str + + Returns + ------- + path_str : str + + """ + import datetime + from os.path import dirname, join + from pathlib import Path + from utils.date_calcs import get_last_month + + today = datetime.date.today() + last_month = get_last_month() + current_year_month = str(last_month.year) + '-' + '{:02d}'.format(last_month.month) + + current_dir = dirname(dirname(__file__)) # the double dirname is equivalent to ../ + rel_path = './output/' + current_year_month + '/' + org_name + path_str = join(current_dir, rel_path) + Path(path_str).mkdir(parents=True, exist_ok=True) + + return path_str + + +def output_path(repo_name, org_name): + """ Creates the path string including repo where .png files will be located + Parameters ---------- repo_name : str @@ -17,17 +46,13 @@ def output_path(repo_name, org_name): path : str """ - import datetime from os.path import dirname, join from pathlib import Path - from utils.date_calcs import get_last_month - today = datetime.date.today() - last_month = get_last_month() - current_year_month = str(last_month.year) + '-' + '{:02d}'.format(last_month.month) + path_str = create_path_str(org_name) current_dir = dirname(dirname(__file__)) # the double dirname is equivalent to ../ - rel_path = './output/' + current_year_month + '/' + org_name + '/' + repo_name + rel_path = path_str + '/' + repo_name path = join(current_dir, rel_path) Path(path).mkdir(parents=True, exist_ok=True) @@ -51,4 +76,4 @@ def output_filename(repo_name, org_name, metric_string): filename = path + '/' + repo_name + '_' + metric_string + '.png' - return filename \ No newline at end of file + return filename