41 lines
1 KiB
Python
Executable file
41 lines
1 KiB
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import filemanip
|
|
import re
|
|
import sys
|
|
|
|
transtbl = [0, 1, 2, 4, 3, 10, 5, 11, 6, 12, 14, 13, 9, 7, 8, 16]
|
|
|
|
translate = False
|
|
if len(sys.argv) > 1:
|
|
if sys.argv[1] == "-t":
|
|
translate = True
|
|
|
|
def repl(mobj):
|
|
date = mobj.group(1)
|
|
adjdate = date
|
|
if len(date) == 5:
|
|
adjdate = "199" + date
|
|
elif len(date) == 6:
|
|
first2 = int(date[0:2])
|
|
if first2 < 70:
|
|
adjdate = "20" + date
|
|
else:
|
|
adjdate = "19" + date
|
|
return adjdate + mobj.group(2)
|
|
|
|
qddb = filemanip.FileStorage("qddb", "/dev/stdin")
|
|
recs = qddb.load()
|
|
if translate:
|
|
newrecs = []
|
|
pat = re.compile(r"^(\d+)(.*)$")
|
|
for rec in recs:
|
|
fields = [None] * 17
|
|
for i in range(len(rec.fields)):
|
|
fields[transtbl[i]] = rec.fields[i]
|
|
if fields[0] is not None:
|
|
fields[0] = pat.sub(repl, fields[0])
|
|
newrecs.append(filemanip.Record(fields))
|
|
recs = newrecs
|
|
csv = filemanip.FileStorage("csv", "/dev/stdout")
|
|
csv.store(recs)
|