From 3848c039a71fb83a583cd2a1c4f51927efcb42c7 Mon Sep 17 00:00:00 2001 From: Alex Murray Date: Fri, 6 Sep 2019 14:14:50 +0930 Subject: [PATCH 1/3] Add support for specifying which API to use --- wttrin.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wttrin.el b/wttrin.el index 512b6a7..45ae637 100644 --- a/wttrin.el +++ b/wttrin.el @@ -22,6 +22,11 @@ :prefix "wttrin-" :group 'comm) +(defcustom wttrin-api-version 1 + "Specifies which version of teh wttrin API to use." + :group 'wttrn + :type '(choice (const 1) (const 2))) + (defcustom wttrin-default-cities '("Taipei" "Keelung" "Taichung" "Tainan") "Specify default cities list for quick completion." :group 'wttrin @@ -39,7 +44,7 @@ (add-to-list 'url-request-extra-headers wttrin-default-accept-language) (with-current-buffer (url-retrieve-synchronously - (concat "http://wttr.in/" query) + (concat "http://v" (number-to-string wttrin-api-version) ".wttr.in/" query) (lambda (status) (switch-to-buffer (current-buffer)))) (decode-coding-string (buffer-string) 'utf-8)))) From ec7963eee3e75782a414c20c41d38e48af59f031 Mon Sep 17 00:00:00 2001 From: Alex Murray Date: Fri, 6 Sep 2019 14:22:45 +0930 Subject: [PATCH 2/3] Filter out parts of v2 API output which xterm-color ignores --- wttrin.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wttrin.el b/wttrin.el index 45ae637..f6e2a61 100644 --- a/wttrin.el +++ b/wttrin.el @@ -63,8 +63,12 @@ (erase-buffer) (insert (xterm-color-filter raw-string)) (goto-char (point-min)) - (re-search-forward "^$") - (delete-region (point-min) (1+ (point))) + (save-excursion + (re-search-forward "^$") + (delete-region (point-min) (1+ (point)))) + (save-excursion + (while (re-search-forward "(B" nil t) + (delete-region (match-beginning 0) (match-end 0)))) (use-local-map (make-sparse-keymap)) (local-set-key "q" 'wttrin-exit) (local-set-key "g" 'wttrin) From 2f25f5203c79486d62c83726ff71794781cb92ad Mon Sep 17 00:00:00 2001 From: Alex Murray Date: Thu, 30 Apr 2020 09:52:25 +0930 Subject: [PATCH 3/3] Set user-agent correctly to ensure we get ansi output --- wttrin.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wttrin.el b/wttrin.el index f6e2a61..de0095b 100644 --- a/wttrin.el +++ b/wttrin.el @@ -40,7 +40,7 @@ (defun wttrin-fetch-raw-string (query) "Get the weather information based on your QUERY." - (let ((url-request-extra-headers '(("User-Agent" . "curl")))) + (let ((url-user-agent "curl")) (add-to-list 'url-request-extra-headers wttrin-default-accept-language) (with-current-buffer (url-retrieve-synchronously