this repo has no description

simplify downloading with get->data :3

+12 -15
+12 -15
weather/weather.bb
··· 12 12 (for [k keyset] 13 13 (vector k (get coll k)))) 14 14 15 + (defn get->data [url get-fn pre-fn] 16 + (let [response (get-fn url) 17 + http-code (:status response)] 18 + (condp = http-code 19 + 200 (-> response :body pre-fn) 20 + 500 (throw (Exception. "Server responded with 500. Rate limit (probably) exceeded. Wait a bit then try again")) 21 + (throw (Exception. (str "Unexpected HTTP status " http-code)))))) 22 + 15 23 (defn download-geonames-data [cache-path country] 16 - (let [base-url "http://download.geonames.org/export/zip/" 17 - url (str base-url country ".zip") 18 - response (curl/get url {:as :bytes})] 19 - (if (= (:status response) 200) 20 - (do (-> response :body io/input-stream (fs/unzip cache-path)) 21 - (str cache-path country ".txt")) 22 - (throw (Exception. str "Wrong HTTP Response Code: " (:status response)))))) 24 + (-> "http://download.geonames.org/export/zip/" 25 + (str country ".zip") 26 + (get->data #(curl/get % {:as :bytes}) io/input-stream) 27 + (fs/unzip cache-path))) 23 28 24 29 (defn get-geonames-data-path 25 30 ([] (get-geonames-data-path cache-path "US")) ··· 39 44 (first (filter 40 45 (fn [{zc :postal_code}] (= zc zipcode)) 41 46 (read-csv-to-maps)))) 42 - 43 - (defn get->data [url get-fn pre-fn] 44 - (let [response (get-fn url) 45 - http-code (:status response)] 46 - (condp = http-code 47 - 200 (-> response :body pre-fn) 48 - 500 (throw (Exception. "Server responded with 500. Rate limit (probably) exceeded. Wait a bit then try again")) 49 - (throw (Exception. (str "Unexpected HTTP status " http-code)))))) 50 47 51 48 (defn get->json [url] (get->data url curl/get json/parse-string)) 52 49