3 ms·
A simple solution in Clojure: (require '[clj-http.client :as client] '[cheshire.core :as json]) (let [url "https://gist.githubusercontent.com/jo
by vladharbuz 12y ago
A simple solution in Clojure:
(require '[clj-http.client :as client]
'[cheshire.core :as json])
(let [url "https://gist.githubusercontent.com/jorin-vogel/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json"
body (:body (client/get url))
data (json/parse-string body true)
data-with-cc (remove #(nil? (:creditcard %)) data)
rows (map #(str (:name %) "," (:creditcard %)) data-with-cc)
csv (str "Name,Credit Card\n" (clojure.string/join "\n" rows))
filename (str (.format (java.text.SimpleDateFormat. "YYYYMMDD") (java.util.Date.)) ".csv")]
(spit filename csv))
- lgas 12y agoThis is a great solution. For fun I had a go at golfing it a bit: (-> "https://gist.githubusercontent.com/jorin-vogel/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json" client/get :body (json/parse-string true) (->> (remove (comp nil? :creditcard)) (map (comp (partial join ",") (juxt :name :creditcard))) (join "\n") (apply str "Name,Credit Card\n") (spit (-> (java.text.SimpleDateFormat. "YYYYMMDD") (.format (java.util.Date.)) (str ".csv"))))) edit: Shorter, requires `(require '[clojure.string :refer [join]])`