Last active
August 14, 2016 21:49
-
-
Save alexjj/3999765812aae8403927a36f58b4365e to your computer and use it in GitHub Desktop.
Switch sign in bank qifs to fix import errors with YNAB
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
import sys | |
def main(argv): | |
for inFilename in argv: | |
if not inFilename.endswith('.qif'): | |
print "Error: expected QIF file" | |
raw_input("Press enter to get outa here...") | |
return 1 | |
outFilename = inFilename.replace('.qif', '.negated.qif') | |
infile = open(inFilename, 'r') | |
outfile = open(outFilename, 'w') | |
negatedCount = 0 | |
for line in infile: | |
if line.startswith('T-'): | |
line = line.replace('T-', 'T', 1) | |
negatedCount = negatedCount + 1 | |
elif line.startswith('T'): | |
line = line.replace('T', 'T-', 1) | |
negatedCount = negatedCount + 1 | |
outfile.write(line) | |
infile.close() | |
outfile.close() | |
print "Found " + str(negatedCount) + " entries to negate. Wrote output to " + outFilename | |
print "Processed " + str(len(argv)) + " files" | |
raw_input("Press enter to get outa here...") | |
return 0 | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment