Skip to content

Instantly share code, notes, and snippets.

@emdeesee
Created January 3, 2019 21:51
Show Gist options
  • Save emdeesee/f8a0c54ad9364e5c365bf4b318607d5d to your computer and use it in GitHub Desktop.
Save emdeesee/f8a0c54ad9364e5c365bf4b318607d5d to your computer and use it in GitHub Desktop.
Get weather forecast from NWS
(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