Created
January 3, 2019 21:51
-
-
Save emdeesee/f8a0c54ad9364e5c365bf4b318607d5d to your computer and use it in GitHub Desktop.
Get weather forecast from NWS
This file contains 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
(ql:quickload :dexador) | |
(ql:quickload :jsown) | |
(ql:quickload :arrows) | |
(use-package :arrows) | |
(defparameter url "https://api.weather.gov/gridpoints/FWD/95,141/forecast") | |
(defun json-val-in (o &rest keys) | |
(reduce (lambda (o k) (jsown:val o k)) keys :initial-value o)) | |
(defun parse-api-response (response) | |
(-<>> response | |
(coerce <> 'list) | |
(mapcar #'code-char) | |
(format nil "~{~a~}") | |
jsown:parse)) | |
(defun forecast (&optional (url url)) | |
(flet ((extract (o) | |
(mapcar (lambda (property) (jsown:val o property)) | |
'("name" "shortForecast" "temperature")))) | |
(-<>> url | |
dex:get | |
parse-api-response | |
(json-val-in <> "properties" "periods") | |
(mapcar #'extract)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment