Mercurial > hg > freeDiameter
diff contrib/tools/org_to_csv @ 1461:a86eb3375b95
add csv_to_fd, org_to_csv tools
csv_to_fd converts CSV files containing RADIUS or Diameter AVP tables
into various formats, including freeDiameter C code and JSON documents.
org_to_csv converts org files into CSV files, suitable for csv_to_fd.
author | Luke Mewburn <luke@mewburn.net> |
---|---|
date | Mon, 09 Mar 2020 21:24:24 +1100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/tools/org_to_csv Mon Mar 09 21:24:24 2020 +1100 @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +""" +Convert |-separated 11-column .org files to CSV, +with first and last empty columns ignored. +""" + +import csv +import fileinput +import re +import sys + +csvout = csv.writer(sys.stdout) +for line in fileinput.input(): + row = re.split(r'\s*\|\s*', line) + row.extend([''] * (10 - len(row))) + csvout.writerow(row[1:10]) + +# vim: set et sw=4 sts=4 :