Skip to content

Instantly share code, notes, and snippets.

@ptsefton ptsefton/
Created Aug 12, 2014

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 =
dataset_dict = {
"name" : filestem,
"notes" : filestem,
"extras" : [{"key": "Sample Interval", "value" : metadata_row[1]}]
header1 =
header2 =
header3 =
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
for row in data:
#print 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
You can’t perform that action at this time.