Last active
December 28, 2015 16:39
Revisions
-
himerzi revised this gist
Nov 18, 2013 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ ;; This is broken and I don't understand why (defn get-londons [] (map #(:sys %) (:list get-london))) ;; Get's name and location of all londons. This works, and I don't understand why (defn get-londons-2 [] (map #(:sys %) (:list (weather-find "London")))) ;; Get coordinates of all Londons @@ -35,5 +35,4 @@ ;;On how many of the next 10 days it will be cloudy (> 40% cloudy) (defn clouds [] (count(filter #(> (% :clouds) 40) (weather-forecast "London,UK" 10)))) -
himerzi created this gist
Nov 18, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ (ns weather.core (:require [clj-http.client :as http])) ;; utility Functions (def weather-api "http://api.openweathermap.org/data/2.5/") (defn weather-find [something] (let [ response (http/get (str weather-api "find") {:query-params {:q something} :as :json})] (:body response))) (defn weather-forecast [loc days] (let [ response (http/get (str weather-api "forecast/daily") {:query-params {:q loc :cnt days :units "metric"} :as :json})] (:list (:body response)))) (defn get-london [] (weather-find "London")) ;; This is broken and I don't understand why (defn get-londons [] (map #(:sys %) (:list get-london))) ;; This works, and I don't understand why (defn get-londons-2 [] (map #(:sys %) (:list (weather-find "London")))) ;; Get coordinates of all Londons (defn get-coords [] (map #(:coord %) (:list (weather-find "London")))) (defn avg [v] (/ (reduce + v) (count v))) ;;What has been the average temp in London over n past days. (defn average-temp-n-days [n] (avg (map #(get-in % [:temp :day])(weather-forecast "London,UK" n)))) ;;On how many of the next 10 days it will be cloudy (> 40% cloudy) (defn clouds [] (count(filter #(> (% :clouds) 40) (weather-forecast "London,UK" 10))))