Last active
June 12, 2023 12:26
-
-
Save romulo-martins/1dc1f744d89f522805ae2901d8eaa6cb to your computer and use it in GitHub Desktop.
Converts from CSV to EDN file
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
| (require '[clojure.data.csv :as csv] | |
| '[clojure.java.io :as io] | |
| '[clojure.string :as str]) | |
| (def in-filename "input-filename.csv") | |
| (def out-filename "output-filename.edn") | |
| (let [csv-data (with-open [reader (io/reader (io/resource in-filename))] | |
| (doall | |
| (csv/read-csv reader))) | |
| maps-data (map zipmap | |
| (->> (first csv-data) ;; First row is the header | |
| (map #(str/replace % #"_" "-")) ;; Example, converts from bla_bla to bla-bla | |
| (map keyword) | |
| repeat) | |
| (rest csv-data))] | |
| (with-open [writer (io/writer out-filename :append true)] | |
| (run! | |
| (fn [row-data] | |
| (.write writer (str row-data "\n"))) | |
| maps-data))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment