Skip to content

Commit

Permalink
ensure output paths exist
Browse files Browse the repository at this point in the history
  • Loading branch information
JHogenboom committed Aug 6, 2024
1 parent 55fa861 commit fa3ff80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion scripts/construct_flashcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ def construct_flashcard(aggregated_data_path, variable, positive_strata, negativ
csv_data = pd.DataFrame(flashcard, columns=[variable]).to_csv(
index=False, lineterminator='\n').replace(' ', '')

# Save the csv flashcard
# Check if path exists or create it
output_dir = os.path.join('data', 'flashcards')
if not os.path.exists(output_dir):
os.makedirs(output_dir)

os.makedirs(output_dir, exist_ok=True)
with open(os.path.join(output_dir, f'{variable}_flashcard.csv'), 'w') as f:
f.write(csv_data)
Expand Down
11 changes: 8 additions & 3 deletions scripts/vantage6_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def _authenticate(config):

if __name__ == "__main__":
# Read configuration and plotting information from command line arguments
vantage6_config_path = sys.argv[1]
plotting_info_path = sys.argv[2]
vantage6_config_path = r"C:\Users\p70087077\PycharmProjects\federated-non-expert-info-portal\data\config.json"
plotting_info_path = r"C:\Users\p70087077\PycharmProjects\federated-non-expert-info-portal\plotting_info.json"

# Attempt to retrieve the configuration and plotting information
with open(vantage6_config_path, "r") as f:
Expand All @@ -140,6 +140,11 @@ def _authenticate(config):

result = retrieve_categorical_descriptives(config, plotting_info)

# Check if the path exists or create it
output_dir = os.path.join("data", "raw")
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Save the result in the appropriate location
with open(os.path.join("data", "raw", "vantage6_result.json"), "w") as f:
with open(os.path.join(output_dir, "vantage6_result.json"), "w") as f:
json.dump(result, f)

0 comments on commit fa3ff80

Please sign in to comment.