Skip to content

Instantly share code, notes, and snippets.

@JPRuskin
Created June 20, 2016 14:06
Show Gist options
  • Save JPRuskin/c55712e20867b3a781ba7152a76804ae to your computer and use it in GitHub Desktop.
Save JPRuskin/c55712e20867b3a781ba7152a76804ae to your computer and use it in GitHub Desktop.
Converts dates in a QIF formatted file from %b to %m.
import sys, re
from datetime import datetime
if sys.argv[1].lower().endswith(".qif"):
redate = re.compile("D\d{2}\/\D{3}\/\d{4}")
with open(sys.argv[1], "r") as infile:
print("Now reading "+infile.name+"...")
with open(sys.argv[1][:-4]+"_converted.qif", 'w') as outfile:
for line in infile:
if redate.match(line):
date_object = datetime.strptime(line,"D%d/%b/%Y\n")
newdate = datetime.strftime(date_object,'%d/%m/%Y')
outfile.write("D"+newdate+"\n")
else:
outfile.write(line)
else:
print("File not found. Please rerun script with a QIF file as the first argument...")
# input("Press Enter to continue...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment