diff options
| author | Carl X. Su <bcbcarl@gmail.com> | 2016-03-06 00:54:12 +0800 |
|---|---|---|
| committer | Carl X. Su <bcbcarl@gmail.com> | 2016-03-06 00:54:12 +0800 |
| commit | 99ba22f0333e9ff72cf1803af49225a99273bca1 (patch) | |
| tree | 79636c8ef4564c5a0a60629ffbf2c45716968bf0 /wttrin.el | |
Initial commit
Diffstat (limited to 'wttrin.el')
| -rw-r--r-- | wttrin.el | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/wttrin.el b/wttrin.el new file mode 100644 index 0000000..b2a3d97 --- /dev/null +++ b/wttrin.el @@ -0,0 +1,47 @@ +;;; wttrin.el --- Emacs frontend for weather web service wttr.in +;; Copyright (C) 2016 Carl X. Su + +;; Author: Carl X. Su <bcbcarl@gmail.com> +;; Version: 0.1.0 +;; Package-Requires: ((emacs "24.4") (xterm-color "20150823.646")) +;; Keywords: comm, weather, wttrin +;; URL: https://github.com/bcbcarl/emacs-wttrin + +;;; Commentary: + +;; Provides the weather information from wttr.in based on your query condition. + +;;; Code: + +(defgroup wttrin nil + "Emacs frontend for weather web service wttr.in." + :prefix "wttrin-" + :group 'comm) + +(defcustom wttrin-query "Taipei" + "Specify a query condition to get the weather information." + :group 'wttrin + :type 'string) + +(defun wttrin-fetch (query) + "Get the weather information based on your QUERY." + (let ((url-request-extra-headers '(("User-Agent" . "curl")))) + (with-current-buffer + (url-retrieve-synchronously + (concat "http://wttr.in/" query) + (lambda (status) (switch-to-buffer (current-buffer)))) + (decode-coding-string (buffer-string) 'utf-8)))) + +(require 'xterm-color) +(defun wttrin-exec () + "Display weather information." + (interactive) + (let* ((title) (name (generate-new-buffer-name (concat "wttr.in - " wttrin-query))) + (buf (get-buffer-create name))) + (switch-to-buffer buf)) + (insert (xterm-color-filter (wttrin-fetch wttrin-query))) + (setq buffer-read-only t)) + +(provide 'wttrin) + +;;; wttrin.el ends here |
