lnav/src/format2csv.py

24 lines
724 B
Python
Raw Permalink Normal View History

2013-07-27 20:04:43 +02:00
2020-05-13 18:38:41 +02:00
import glob
2013-07-27 20:04:43 +02:00
import csv
import sys
import json
def main(args):
2020-05-13 18:38:41 +02:00
with open(args[1], 'w') as ofp:
out = csv.writer(ofp)
for format_path in sorted(glob.glob("%s/*.json" % args[2])):
with open(format_path) as fp:
format_dict = json.load(fp)
2013-07-27 20:04:43 +02:00
2020-05-13 18:38:41 +02:00
for key in sorted(format_dict):
value = format_dict[key]
2020-09-29 23:14:43 +02:00
if not isinstance(value, dict):
continue
2022-03-31 17:59:19 +02:00
if 'title' not in value:
raise Exception("format '%s' is missing 'title'" % key)
2020-05-13 18:38:41 +02:00
out.writerow((value['title'], key, value['description']))
2013-07-27 20:04:43 +02:00
if __name__ == "__main__":
sys.exit(main(sys.argv))