Last active
October 1, 2024 09:51
-
-
Save dadatuputi/b961882b8c8535aa30aacbdc446219c4 to your computer and use it in GitHub Desktop.
Wise CSV to YNAB CSV
This file contains 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 pandas as pd | |
from enum import Enum | |
class Direction(Enum): | |
OUT = -1 | |
IN = 1 | |
# Get input and output file as arguments | |
parser = argparse.ArgumentParser(description="Convert Wise CSV to YNAB CSV") | |
parser.add_argument('-o', '--output', default="ynab.csv", help="CSV Filename to write to") | |
parser.add_argument('-d', '--debug', help="Debug by printing out text of supplied PDF", action='store_true') | |
parser.add_argument('input', help="Wise CSV to import") | |
args = parser.parse_args() | |
# Open Wise | |
wise = pd.read_csv(args.input) | |
# Filter out CANCELED transactions | |
wise = wise[wise['Status'] != 'CANCELLED'] | |
# Add multiplier to get value into single column | |
wise['Mult'] = wise.apply(lambda row: Direction[row['Direction']].value, axis=1) | |
ynab = pd.DataFrame() | |
ynab['Date'] = pd.to_datetime(wise['Finished on']).dt.strftime('%Y-%m-%d') | |
ynab['Payee'] = wise.apply(lambda row: row['Target name'] if Direction[row['Direction']] == Direction.OUT else row['Source name'], axis=1) | |
ynab['Memo'] = wise.apply(lambda row: f"{row['Reference']}; {row['ID']}" if pd.notna(row['Reference']) else row['ID'], axis=1) | |
ynab['Amount'] = wise['Target amount (after fees)'] * wise['Mult'] | |
print("Writing {} transactions to {}".format(len(ynab), args.output)) | |
ynab.to_csv(args.output, index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment