Created
July 17, 2012 04:51
-
-
Save kovshenin/3127242 to your computer and use it in GitHub Desktop.
Rewrite m/d/y dates to Y-m-d in a PayPal CSV export
This file contains hidden or 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
""" | |
This script will rewrite the date column in a PayPal CSV | |
export from m/d/y to Y-m-d format. | |
Usage: | |
# python fix-paypal-csv-dates.py input_file.csv > output_file.csv | |
""" | |
import csv, sys | |
from time import strptime, strftime | |
filename = sys.argv[1] | |
try: | |
reader = csv.reader(open(filename, 'rb'), delimiter=',', quotechar='"') | |
writer = csv.writer(sys.stdout, delimiter=',', quotechar='"') | |
except IOError as e: | |
print e | |
exit() | |
for row in reader: | |
try: | |
t = strptime(row[0], "%m/%d/%Y") | |
row[0] = strftime("%Y-%m-%d", t) | |
except ValueError: | |
pass | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment