Skip to content

Instantly share code, notes, and snippets.

@SneakyPeet
Created April 3, 2019 08:16
Show Gist options
  • Save SneakyPeet/dfc6b8b959a50ad7d0c7a5da9ee54da0 to your computer and use it in GitHub Desktop.
Save SneakyPeet/dfc6b8b959a50ad7d0c7a5da9ee54da0 to your computer and use it in GitHub Desktop.
Parse fnb and ynab exoport csv
(defn parse-fnb [path]
(let [fnb-csv-rows
(as-> (slurp (clojure.java.io/file path)) x
(clojure.string/split x #"\n")
(drop 6 x)
(map #(clojure.string/split % #", ") x))
header (->> fnb-csv-rows first (map keyword))
rows (->> fnb-csv-rows
rest
(map #(zipmap header %))
(map #(-> %
(update :Amount read-string)
(update :Balance read-string))))]
rows))
(defn parse-ynab [path]
(let [csv-rows
(as-> (slurp (clojure.java.io/file path)) x
(clojure.string/replace x #"\"" "")
(clojure.string/split x #"\r\n")
(map #(clojure.string/split % #",") x))
header (->> csv-rows
first
(map #(clojure.string/replace % " " "-"))
(map #(clojure.string/replace % "/" "-"))
(map keyword))
rows (->> csv-rows
rest
(map #(zipmap header %))
(map #(-> %
(update :Inflow read-string)
(update :Outflow read-string)
(update :Date (fn [d] (java.util.Date. d)))))
(map #(assoc % :Amount (- (:Inflow %) (:Outflow %))))
(filter #(= "Gold Credit" (:Account %)))
(filter #(> (.getTime (:Date %)) (.getTime (java.util.Date. "2019/01/01")))))]
rows))
(defn duplicate-transactions [ynab-data]
(->> ynab-data
(group-by :Amount)
(map (fn [[a t]]
[a (count t)]))
(filter #(> (second %) 1))
(sort-by first)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment