Created
January 30, 2024 15:02
-
-
Save grafuls/73810576cf9a078f5e3a7c301e33b7f2 to your computer and use it in GitHub Desktop.
Quads setup script which iterates through the key value pairs on the quads.yml configuration file and provides the defined values as defaults for the inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/env python | |
import yaml | |
def prompt_user(config): | |
for key in config.keys(): | |
if isinstance(config[key], dict): | |
config[key] = prompt_user(config[key]) | |
else: | |
# Convert the key into a human-friendly format | |
prompt = ' '.join(word.capitalize() for word in key.split('_')) | |
new_value = input(f"Enter {prompt} (current: {config[key]}): ") | |
if new_value: | |
config[key] = new_value | |
return config | |
def read_yaml(input_file): | |
with open(input_file, 'r') as infile: | |
return yaml.safe_load(infile) | |
def write_yaml(config, output_file): | |
with open(output_file, 'w') as outfile: | |
yaml.dump(config, outfile, default_flow_style=False) | |
if __name__ == "__main__": | |
config = read_yaml('quads.yaml') | |
new_config = prompt_user(config) | |
write_yaml(new_config, 'new_config.yaml') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment