Skip to content

Commit 102155a

Browse files
author
Bastien Guerry
committed
src/annuaire-service-public-enrichi.clj: Minor enhancements
1 parent 4f9ac46 commit 102155a

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/annuaire-service-public-enrichi.clj

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66

77
;; Get the json annuaire file
88
(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.))]
1515
(.getNextEntry stream)
1616
(println "Creating annuaire.json")
1717
(io/copy stream (io/file "annuaire.json")))
1818

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))
2726

2827
;; Add service_sup
2928
(println "Adding service_sup...")
@@ -86,13 +85,15 @@
8685

8786
;; Add service_top
8887
(println "Adding service_top...")
88+
8989
(doseq [a (filter #(seq (:service_sup (val %))) @annuaire)]
9090
(swap! annuaire update-in
9191
[(key a)]
9292
conj {:service_top (get-ancestor (:service_sup (val a)))}))
9393

9494
;; Output annuaire_sup.json
9595
(println "Creating annuaire_sup.json...")
96+
9697
(spit "annuaire_sup.json"
9798
(json/generate-string
9899
(map (fn [[k v]] (conj v {:id k})) @annuaire)
@@ -102,4 +103,3 @@
102103
(spit "annuaire_tops.json"
103104
(-> (map #(hash-map % (:nom (get @annuaire %))) tops)
104105
(json/generate-string {:pretty true})))
105-

0 commit comments

Comments
 (0)