Last active
December 28, 2015 16:39
-
-
Save himerzi/7530384 to your computer and use it in GitHub Desktop.
weather homework exercises
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 characters
(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))) | |
;; 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 | |
(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)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment