Skip to content

Instantly share code, notes, and snippets.

@isoraqathedh
Created July 16, 2017 16:49
Show Gist options
  • Select an option

  • Save isoraqathedh/d2a414f4b55ce4b84fd1ac5f3b61d85c to your computer and use it in GitHub Desktop.

Select an option

Save isoraqathedh/d2a414f4b55ce4b84fd1ac5f3b61d85c to your computer and use it in GitHub Desktop.
Grab currency information.
#!/usr/local/bin/sbcl --script
(load "~/quicklisp/setup.lisp")
(ql:quickload '(:yason :drakma) :silent t)
(let ((drakma:*text-content-types* `(("application" . "json")
("text" . "json")
,@drakma:*text-content-types*))
(yason:*parse-object-as* :alist))
(with-open-file (s (make-pathname :name "cache"
:type "conf"
:defaults *load-pathname*)
:if-exists :overwrite
:if-does-not-exist :create
:direction :output)
(loop with data = (yason:parse
(drakma:http-request
"https://api.fixer.io/latest?base=HKD"))
with date = (cdr (assoc "date" data :test #'string=))
with rate-list = (cdr (assoc "rates" data :test #'string=))
initially (format s "~&date ~a" date)
for (currency-name . currency-rate) in rate-list
do (format s "~&~a ~9,5f" currency-name (/ currency-rate)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment