Created
March 7, 2012 22:59
-
-
Save JoeGermuska/1996940 to your computer and use it in GitHub Desktop.
Example of script to make a csvkit fixed width schema from IL Board of Ed School Report Card file layouts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import csv | |
input_file = sys.argv[1] | |
r = csv.reader(open(input_file)) | |
w = csv.writer(sys.stdout) | |
w.writerow(['column','start','length']) | |
for row in r: | |
try: | |
if row[0].isdigit(): | |
col = row[5].strip() | |
col_plus = filter(None,map(str.strip,row[1:3])) | |
if col_plus: | |
col = "%s (%s)" % (col,','.join(col_plus)) | |
start = int(row[7]) | |
length = int(row[8]) - start | |
w.writerow([col,start,length]) | |
except Exception,e: | |
sys.stderr.write("%s\n" % e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment