Created
July 16, 2017 16:49
-
-
Save isoraqathedh/d2a414f4b55ce4b84fd1ac5f3b61d85c to your computer and use it in GitHub Desktop.
Grab currency information.
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
| #!/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