double-arrow selector
[naja.git] / tools / gen_json.py
1 #!/usr/bin/env python
2
3 import json
4 import os
5
6 import yaml
7
8
9 def main():
10     data = os.path.join(os.path.dirname(__file__), '..', 'data')
11     deck_dir = os.path.join(data, 'location_decks')
12
13     for yaml_fn in os.listdir(deck_dir):
14         basename, extension = os.path.splitext(yaml_fn)
15         if extension != '.yaml':
16             continue
17         json_fn = basename + '.json'
18
19         yaml_path = os.path.join(deck_dir, yaml_fn)
20         json_path = os.path.join(deck_dir, json_fn)
21
22         with open(yaml_path) as yaml_f:
23             obj = yaml.safe_load(yaml_f)
24         with open(json_path, 'w') as json_f:
25             json.dump(obj, json_f, indent=2)
26
27
28 if __name__ == '__main__':
29     main()