Skip to content

Instantly share code, notes, and snippets.

@tilacog
Created May 19, 2017 14:08
Show Gist options
  • Save tilacog/adb9756a625abf899a65d73bcd30a0dc to your computer and use it in GitHub Desktop.
Save tilacog/adb9756a625abf899a65d73bcd30a0dc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
import sys
def pprint_specfile(path, filters):
record_fmt = '{r[name]}: {r[label]}'
field_fmt = ' {f[order]}-{f[name]}'
with open(path) as fh:
data = json.load(fh)
for record in data:
if filters and record['name'] not in filters:
continue
print(record_fmt.format(r=record))
for field in record['fields']:
print(field_fmt.format(f=field))
if __name__ == '__main__':
path, *filters = sys.argv[1:]
pprint_specfile(path, filters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment