|
|
|
@ -6,17 +6,23 @@
|
|
|
|
|
[beherbergung.model.offer-mapping.lifeline]
|
|
|
|
|
[beherbergung.model.offer :as offer]
|
|
|
|
|
[beherbergung.model.ngo :as ngo]
|
|
|
|
|
[clj-http.client :as client]
|
|
|
|
|
[clojure.edn]))
|
|
|
|
|
|
|
|
|
|
(defn geocode
|
|
|
|
|
[record]
|
|
|
|
|
(assoc record
|
|
|
|
|
:place_lon 12.34
|
|
|
|
|
:place_lat 51.34))
|
|
|
|
|
(defn geocode [record]
|
|
|
|
|
(let [params {:city (:place_city record)}
|
|
|
|
|
result (client/get "https://nominatim.openstreetmap.org/search?format=json&limit=1"
|
|
|
|
|
{:accept :json :as :json :query-params params})
|
|
|
|
|
result_ok (when (= 200 (:status result))
|
|
|
|
|
(first (:body result)))]
|
|
|
|
|
(println (or (:display_name result_ok)
|
|
|
|
|
result))
|
|
|
|
|
(assoc record
|
|
|
|
|
:place_lon (:lon result_ok)
|
|
|
|
|
:place_lat (:lat result_ok))))
|
|
|
|
|
|
|
|
|
|
(defn update-offers [table]
|
|
|
|
|
(let [ngo:id "lifeline_beherbergung" ;; TODO
|
|
|
|
|
{:keys [tx-fn-put tx-fn-call]} db_ctx]
|
|
|
|
|
(defn update-offers [ngo:id table]
|
|
|
|
|
(let [{:keys [tx-fn-put tx-fn-call]} db_ctx]
|
|
|
|
|
(tx-fn-put :update-offer
|
|
|
|
|
'(fn [ctx eid doc ngo:id]
|
|
|
|
|
(let [db (xtdb.api/db ctx)
|
|
|
|
@ -28,19 +34,22 @@
|
|
|
|
|
(doseq [record table
|
|
|
|
|
:let [existingId (when (:id_tmp record)
|
|
|
|
|
(str "offer_" (:id_tmp record)))]]
|
|
|
|
|
;; TODO: skip geocoding when it was already successfully done at an earlier import
|
|
|
|
|
(tx-fn-call :update-offer (or existingId (uuid))
|
|
|
|
|
(geocode record)
|
|
|
|
|
ngo:id))))
|
|
|
|
|
|
|
|
|
|
(defn import! []
|
|
|
|
|
(let [table (if (:import-file env)
|
|
|
|
|
(unify (clojure.edn/read-string (slurp (:import-file env)))
|
|
|
|
|
beherbergung.model.offer-mapping.lifeline/mapping)
|
|
|
|
|
(clojure.edn/read-string (slurp "./data/import/example.edn")) ;; till conflict between `specialist-server.type` and `with-gen` is fixed
|
|
|
|
|
#_(gen/sample (s/gen ::offer)))]
|
|
|
|
|
(println "Records to be imported:" (count table))
|
|
|
|
|
(update-offers table))
|
|
|
|
|
(println "imported :)"))
|
|
|
|
|
(if-not (:import-ngo env)
|
|
|
|
|
(println "No IMPORT_NGO defined")
|
|
|
|
|
(let [table (if (:import-file env)
|
|
|
|
|
(unify (clojure.edn/read-string (slurp (:import-file env)))
|
|
|
|
|
beherbergung.model.offer-mapping.lifeline/mapping)
|
|
|
|
|
(clojure.edn/read-string (slurp "./data/import/example.edn")) ;; till conflict between `specialist-server.type` and `with-gen` is fixed
|
|
|
|
|
#_(gen/sample (s/gen ::offer)))]
|
|
|
|
|
(println "Records to be imported:" (count table))
|
|
|
|
|
(update-offers (:import-ngo env) table)
|
|
|
|
|
(println "import finished :)"))))
|
|
|
|
|
|
|
|
|
|
(comment
|
|
|
|
|
(import!)
|
|
|
|
|