Created
August 12, 2014 21:55
-
-
Save ptsefton/de681f7ed71d89178155 to your computer and use it in GitHub Desktop.
Quick incomplete sample code for extracting CSV and CKAN-flavoured metadata from a TOA5 file
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
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