Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for selecting the unit system #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ You can also specify default HTTP request Header for Accept-Language:
(setq wttrin-default-accept-language '("Accept-Language" . "zh-TW"))
```

As well as the unit system, "m" for metric and "u" for USCS/imperial (the default is to choose based on your location):

```elisp
(setq wttrin-unit-system "m")
```

Then run `M-x wttrin` to get the information.

When the weather is displayed you can press `q` to quit the buffer or `g` to query for another city.
Expand Down
14 changes: 13 additions & 1 deletion wttrin.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,25 @@
:type '(list)
)

(defcustom wttrin-unit-system nil
"Specify the units. use 'm' for 'metric', 'u' for 'USCS, or
nil for location based units (the default)."
:group 'wttrin
:type 'string
)

(defun wttrin-additional-url-params ()
"Concatenate any extra stuff into the URL here."
(concat "?" wttrin-unit-system)
)

(defun wttrin-fetch-raw-string (query)
"Get the weather information based on your QUERY."
(let ((url-request-extra-headers '(("User-Agent" . "curl"))))
(add-to-list 'url-request-extra-headers wttrin-default-accept-language)
(with-current-buffer
(url-retrieve-synchronously
(concat "http://wttr.in/" query)
(concat "http://wttr.in/" query (wttrin-additional-url-params))
(lambda (status) (switch-to-buffer (current-buffer))))
(decode-coding-string (buffer-string) 'utf-8))))

Expand Down