Skip to content

Instantly share code, notes, and snippets.

@etyurkin
Last active October 13, 2018 00:14
Show Gist options
  • Save etyurkin/961d2bd50523263106053736d2ed90fe to your computer and use it in GitHub Desktop.
Save etyurkin/961d2bd50523263106053736d2ed90fe to your computer and use it in GitHub Desktop.
Emacs Lisp: check parcel location and status from Canada Post
(require 'json)
(defun canadapost-status (tracking-number)
"Check parcel location and status from Canada Post"
(interactive "MTracking number: ")
(with-temp-buffer
(url-insert-file-contents
(format "https://www.canadapost.ca/trackweb/rs/track/json/package?pins=%s" tracking-number))
(let* ((json-object-type 'hash-table)
(json-array-type 'list)
(json-key-type 'string)
(json (car (json-read)))
(event (gethash "latestEvent" json)))
(if event
(let ((datetime (gethash "datetime" event))
(location (gethash "locationAddr" event)))
(message (format "[%s %s] %s, %s: %s"
(gethash "date" datetime)
(gethash "time" datetime)
(capitalize (gethash "countryNmEn" location))
(capitalize (gethash "city" location))
(gethash "descEn" event))))
(message (gethash "descEn" (gethash "error" json)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment