Skip to content

Instantly share code, notes, and snippets.

@sbliven sbliven/nab2ynab.R
Created Dec 11, 2017

Embed
What would you like to do?
Convert bank transaction data from Neue Aargauer Bank CSV files to the format expected by youneedabudget.com
#!/usr/bin/env Rscript
library(readr)
library(dplyr)
library(magrittr)
args = commandArgs(trailingOnly=TRUE)
if (length(args) != 2) {
stop("usage: nab2ynab.R nab.csv ynab.csv", call.=FALSE)
}
infile <- args[1]
outfile <- args[2]
data = read_csv(infile,skip = 6)
data %<>% tbl_df
ynab <-
data %>%
filter(grepl("^[0-9][0-9]\\.[0-9][0-9]\\.[0-9]{4}$",`Booking Date`)) %>%
transmute(Date=sub("^([0-9][0-9])\\.([0-9][0-9])\\.([0-9]{4})$","\\1/\\2/\\3",`Booking Date`),
Payee=sub("^([^,]*),.*$","\\1",Text),
Category="",
Memo=sub("^[^,]*,(.*)$","\\1",Text),
Outflow=Debit,
Inflow=Credit) %>%
tbl_df
write_csv(ynab, outfile, na="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.