Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Quick incomplete sample code for extracting CSV and CKAN-flavoured metadata from a TOA5 file
import csv
import StringIO
filestem = "WTC12_Table2_20140831"
in_file = "/Users/pt/Downloads/%s.dat" % filestem
out_file = "/Users/pt/Downloads/%s.csv" % filestem
def TOA52csv(in_file, out_file):
data = csv.reader(open(in_file))
writer = csv.writer(open(out_file, "w"))
print dir(data)
metadata_row = data.next()
dataset_dict = {
"name" : filestem,
"notes" : filestem,
"extras" : [{"key": "Sample Interval", "value" : metadata_row[1]}]
}
header1 = data.next()
header2 = data.next()
header3 = data.next()
i = 0
new_header = []
for field in header1:
new_header.append("%s :: %s :: %s" % (field, header2[i], header3[i]))
i = i + 1
#print new_header
writer.writerow(new_header)
for row in data:
#print row
writer.writerow(row)
return dataset_dict
print TOA52csv(in_file, out_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment