Created
May 28, 2020 15:33
-
-
Save tcoliver/7e41f595d331ff0851e79f5f9c32c587 to your computer and use it in GitHub Desktop.
Simple script for converting a transaction CSV exported from USAA into a YNAB import compatible format.
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 argparse | |
| import csv | |
| import pathlib | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("infile", type=str, help="CSV file exported from USAA's web portal") | |
| parser.add_argument( | |
| "outfile", | |
| nargs="?", | |
| type=str, | |
| help="CSV file to create. (default: 'ynab_out.csv' within infile's parent directory)", | |
| ) | |
| args = parser.parse_args() | |
| if args.outfile is None: | |
| args.outfile = pathlib.Path(args.infile).parent / "ynab_out.csv" | |
| with open(args.infile, "r", newline="") as infile, open(args.outfile, "w", newline="") as outfile: | |
| ussa_reader = csv.DictReader( | |
| infile, | |
| fieldnames=["Status", "Blank1", "Date", "Blank2", "Payee", "Memo", "Amount"], | |
| ) | |
| ynab_writer = csv.DictWriter( | |
| outfile, | |
| fieldnames=["Date", "Payee", "Memo", "Amount"], | |
| extrasaction="ignore" | |
| ) | |
| ynab_writer.writeheader() | |
| ynab_writer.writerows(ussa_reader) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment