|
6 | 6 |
|
7 | 7 | ;; Get the json annuaire file |
8 | 8 | (println "Fetching annuaire as a zip file from data.gouv.fr...") |
9 | | -(def annuaire-zip-url |
10 | | - "https://www.data.gouv.fr/fr/datasets/r/d0158eb2-6772-49c2-afb1-732e573ba1e5") |
11 | | -(let [stream (-> (curl/get annuaire-zip-url {:as :bytes}) |
12 | | - :body |
13 | | - (io/input-stream) |
14 | | - (java.util.zip.ZipInputStream.))] |
| 9 | + |
| 10 | +(let [annuaire-zip-url "https://www.data.gouv.fr/fr/datasets/r/d0158eb2-6772-49c2-afb1-732e573ba1e5" |
| 11 | + stream (-> (curl/get annuaire-zip-url {:as :bytes}) |
| 12 | + :body |
| 13 | + (io/input-stream) |
| 14 | + (java.util.zip.ZipInputStream.))] |
15 | 15 | (.getNextEntry stream) |
16 | 16 | (println "Creating annuaire.json") |
17 | 17 | (io/copy stream (io/file "annuaire.json"))) |
18 | 18 |
|
19 | | -;; Create a variable containing the original data |
20 | | -(def annuaire |
21 | | - (->> (json/parse-string (slurp "annuaire.json") true) |
22 | | - :service |
23 | | - (map (fn [a] [(:id a) (select-keys a [:hierarchie :nom :sigle])])) |
24 | | - flatten |
25 | | - (apply hash-map) |
26 | | - atom)) |
| 19 | +;; Create a variable containing the original annuaire data |
| 20 | +(def annuaire (atom {})) |
| 21 | +(->> (json/parse-string (slurp "annuaire.json") true) |
| 22 | + :service |
| 23 | + (map (fn [a] [(:id a) (select-keys a [:hierarchie :nom :sigle])])) |
| 24 | + (into {}) |
| 25 | + (reset! annuaire)) |
27 | 26 |
|
28 | 27 | ;; Add service_sup |
29 | 28 | (println "Adding service_sup...") |
|
86 | 85 |
|
87 | 86 | ;; Add service_top |
88 | 87 | (println "Adding service_top...") |
| 88 | + |
89 | 89 | (doseq [a (filter #(seq (:service_sup (val %))) @annuaire)] |
90 | 90 | (swap! annuaire update-in |
91 | 91 | [(key a)] |
92 | 92 | conj {:service_top (get-ancestor (:service_sup (val a)))})) |
93 | 93 |
|
94 | 94 | ;; Output annuaire_sup.json |
95 | 95 | (println "Creating annuaire_sup.json...") |
| 96 | + |
96 | 97 | (spit "annuaire_sup.json" |
97 | 98 | (json/generate-string |
98 | 99 | (map (fn [[k v]] (conj v {:id k})) @annuaire) |
|
102 | 103 | (spit "annuaire_tops.json" |
103 | 104 | (-> (map #(hash-map % (:nom (get @annuaire %))) tops) |
104 | 105 | (json/generate-string {:pretty true}))) |
105 | | - |
0 commit comments