Skip to content

Instantly share code, notes, and snippets.

@sbliven
Created December 11, 2017 20:51
Show Gist options
  • Save sbliven/f82ccf7ce02796c2e39a4f235fa8f397 to your computer and use it in GitHub Desktop.
Save sbliven/f82ccf7ce02796c2e39a4f235fa8f397 to your computer and use it in GitHub Desktop.
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