Skip to content

Commit 05403ab

Browse files
committed
Added a make command for generating json.
1 parent 28fcac9 commit 05403ab

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ setup:
22
pip install -r scripts/requirements-test.txt
33

44
validate: setup ## Validate data
5-
goodtables datapackage datapackage.json
5+
@echo Validation command not yet implemented.
6+
7+
json: setup ## Generate JSON from YAML
8+
python scripts/yaml2json.py < data/committees.yml > outputs/committees.json
69

710
dummy: ## Perform a dummy action with outputs
811
python scripts/run_dummy_action.py

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Usage: make <command>
2323
where <command> is one of the following:
2424
2525
validate Validate data
26+
json Generate JSON from YAML
2627
dummy Perform a dummy action with outputs
2728
```
2829

scripts/yaml2json.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# convert yaml to json
2+
# pip3 install pyyaml
3+
# http://pyyaml.org/wiki/PyYAMLDocumentation
4+
# py3 yaml2json.py < ~/code/manpow/homeland/heartland/puphpet/config.yaml
5+
# gist https://gist.github.com/noahcoad/51934724e0896184a2340217b383af73
6+
7+
import json
8+
import sys
9+
import yaml
10+
11+
12+
# See: http://stackoverflow.com/a/25895504
13+
def date_handler(obj):
14+
if hasattr(obj, 'isoformat'):
15+
return obj.isoformat()
16+
else:
17+
raise TypeError
18+
19+
yml = yaml.load(sys.stdin)
20+
21+
sys.stdout.write(json.dumps(yml,
22+
sort_keys=True,
23+
indent=2,
24+
default=date_handler))

0 commit comments

Comments
 (0)