8 data = os.path.join(os.path.dirname(__file__), '..', 'data')
10 deck_dir = os.path.join(data, 'location_decks')
11 convert_to_json(deck_dir, update)
12 puzzle_dir = os.path.join(deck_dir, 'puzzles')
13 convert_to_json(puzzle_dir, update)
16 def convert_to_json(directory, update=True):
17 for yaml_fn in os.listdir(directory):
18 basename, extension = os.path.splitext(yaml_fn)
19 if extension != '.yaml':
21 json_fn = basename + '.json'
23 yaml_path = os.path.join(directory, yaml_fn)
24 json_path = os.path.join(directory, json_fn)
26 if not update and os.path.exists(json_path):
30 with open(yaml_path) as yaml_f:
31 obj = yaml.safe_load(yaml_f)
32 with open(json_path, 'w') as json_f:
33 json.dump(obj, json_f, indent=2)
36 if __name__ == '__main__':