Skip to content

Instantly share code, notes, and snippets.

@finoradin
Created August 13, 2013 23:27
Show Gist options
  • Save finoradin/6226706 to your computer and use it in GitHub Desktop.
Save finoradin/6226706 to your computer and use it in GitHub Desktop.
A pretty jenky way of finding the date in an XML blob and putting it in the correct column.
import csv, re, argparse, os
parser = argparse.ArgumentParser(description="Helper for fixing xfr stn metadata. yolo.")
parser.add_argument('-i', '--input', type=str, required=True, help='full path to csv')
args = parser.parse_args()
csv_file = os.path.normpath(args.input)
with open(csv_file, 'rb') as xfrstncsv:
reader = csv.reader(xfrstncsv, delimiter=',', quotechar='"')
writefile = open(csv_file+'_fixed.csv', 'wb')
writer = csv.writer(writefile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
i = 1
for row in reader:
xml_blob = row[11]
m = "".join(re.findall ( '<date>(.*?)</date>', xml_blob, re.DOTALL))
print "Row " + str(i) +" created date is: " + m
writer.writerow([row[0],str(row[1]),row[2],row[3],m,row[5],row[6],row[7],row[8],row[9],row[10],row[11]])
i = i + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment