-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_history_csv.bb.clj
36 lines (32 loc) · 1.24 KB
/
parse_history_csv.bb.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bb
(ns update-surveys
(:require
[clojure.edn :as edn]
[clojure.string :as string]
[cheshire.core :as json])
(:import [java.time LocalDate]
[java.time.format DateTimeFormatter]))
(def src-date-pattern (DateTimeFormatter/ofPattern "d/M/yyyy"))
(def out-date-pattern (DateTimeFormatter/ofPattern "yyyy-MM-dd"))
(defn format-date
[^String date]
(let [d (LocalDate/parse date src-date-pattern)]
(.format d out-date-pattern)))
;; https://stackoverflow.com/a/62915361/3592771
(defn remove-non-printable-chars
[^String s]
(string/replace s #"\p{C}" ""))
;;; parsed csv file with history water levels and render into JSON
;;; file downloaded from:
;;; https://data.gov.il/dataset/https-www-data-gov-il-dataset-682/resource/2de7b543-e13d-4e7e-b4c8-56071bc4d3c8
(let [input (slurp (first *command-line-args*))
output (second *command-line-args*)
parsed (reduce
(fn [arr line]
(let [[d l] (string/split line #", ")]
(conj arr
{:date (format-date (remove-non-printable-chars d))
:level (edn/read-string l)})))
[]
(string/split-lines input))]
(spit output (json/generate-string parsed)))