backend: geocode
parent
e381675a39
commit
2da7d0fe27
|
@ -26,6 +26,8 @@
|
|||
[crypto-random "1.2.1"]
|
||||
[buddy/buddy-sign "3.4.333"]
|
||||
#_[com.draines/postal "2.0.4"]
|
||||
;; ajax (geocoding)
|
||||
[clj-http "3.12.3"]
|
||||
;; logging
|
||||
[org.clojure/tools.logging "1.2.4"]
|
||||
[org.slf4j/slf4j-api "2.0.0-alpha6"]
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
(s/def ::admin-gpg-id string?)
|
||||
|
||||
(s/def ::import-file (s/nilable string?))
|
||||
(s/def ::import-ngo (s/nilable string?))
|
||||
|
||||
(s/def ::mail-host string?)
|
||||
(s/def ::mail-user string?)
|
||||
|
@ -43,6 +44,7 @@
|
|||
::admin-passphrase
|
||||
::admin-gpg-id
|
||||
::import-file
|
||||
::import-ngo
|
||||
;::mail-host ::mail-user ::mail-pass ::mail-port ::mail-from
|
||||
]))
|
||||
|
||||
|
|
|
@ -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!)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
{:xt/id "login_max_mueller"
|
||||
:xt/spec :beherbergung.model.login/record
|
||||
:mail "praxis@max.mueller.de"
|
||||
:mail "max.mueller@warhelp.eu"
|
||||
:password-hash "100$12$argon2id$v13$hq47jacLIYoiNMD9kdyy+w$ISDi+bSSTmsgqu648LQLv7ySU+lG2VGKRfa06HNfjzk$$$" #_"i!A;z\"'^G3Q)w])%83)" }
|
||||
|
||||
{:xt/id "login_crewing"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
:db-validate true
|
||||
|
||||
:import-file nil #_"./data/sample-data/example.edn"
|
||||
:import-ngo "warhelp"
|
||||
|
||||
;:mail-host ""
|
||||
;:mail-user ""
|
||||
|
|
Loading…
Reference in New Issue