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

Raw html instad of wttrin #16

Open
hummuscience opened this issue May 4, 2020 · 12 comments
Open

Raw html instad of wttrin #16

hummuscience opened this issue May 4, 2020 · 12 comments

Comments

@hummuscience
Copy link

I setup wttrin as follows:

(use-package wttrin
  :init
  (setq wttrin-default-cities          '("Heidelberg" "Tel-Aviv")
        wttrin-default-accept-language '("Accept-Language" . "en-US")))

I am using GNU Emacs 26.3

When I run wttrin and pick the city, I get a raw html file instead of a rendered page https://pastebin.com/aTcvQvj3

I am sure I am missing something essential here. Thanks in advance!

@emacle
Copy link

emacle commented May 6, 2020

soloved url-request-extra-headers '(("User-Agent" . "curl")))) cannot override url-user-agent , change to the following code

(defun wttrin-fetch-raw-string (query)
  "Get the weather information based on your QUERY."
  (let ((url-user-agent "curl"))  

@SodaLover
Copy link

This does not fix it for me.

@emacle
Copy link

emacle commented May 11, 2020

@SodaLover
ed56927

(defun wttrin-fetch-raw-string (query)
  "Get the weather information based on your QUERY."
  (let ((url-request-extra-headers '(("User-Agent" . "curl"))))

change to

(defun wttrin-fetch-raw-string (query)
  "Get the weather information based on your QUERY."	
 (let ((url-user-agent "curl"))

then byte-compile the .el file

@dagst47
Copy link

dagst47 commented May 28, 2020

This worked for me.
Step by step clarification, in case someone else like me finds this:

  1. Go to the directory where your packages are kept (mine are under ~/.emacs.d/elpa/wttrin*
  2. Edit the wttrin.el as emacle wrote above, replacing the line (let ((url-request-extra-headers...) with the (let ((url-user agent...) statement.
  3. move or delete the file that ends in .elc
  4. If you're using use-package for your config, just relaunch emacs. There are probably other ways, but was the easiest for me. It will recreate the .elc file that you moved/deleted using the newly modified .el file.

Thank you for the fix emacle!

@brannala
Copy link

I was experiencing the html display problem as well (GNU Emacs 26.3) but the above suggestions did not fix the problem. However, making the above changes and adding a flag to the wttrin url call specifying text format did the trick for me. Here are the changes to wttrin.el that worked for me.
Change:
(defun wttrin-fetch-raw-string (query) "Get the weather information based on your QUERY." (let ((url-request-extra-headers '(("User-Agent" . "curl"))))
To:
(defun wttrin-fetch-raw-string (query) "Get the weather information based on your QUERY." (let ((url-user-agent "curl"))
Change:
(concat "http://wttr.in/" query)
To:
(concat "http://wttr.in/" query "?A")

@MooersLab
Copy link

I too have GNU emacs 26.3. It is on Mac OS 10.15.

I followed @brannala's recommendation and it worked!

@beacoder
Copy link

beacoder commented Jul 28, 2020

Try this one, it worked for me.

;; fix wttrin buffer render issue
(advice-remove 'wttrin-query 'render-wttrin-buffer)
(defun render-wttrin-buffer (ignore-args)
"Render the wtrrin buffer."
(read-only-mode -1)
(shr-render-region (point-min) (point-max))
(delete-trailing-whitespace)
(read-only-mode t))
(advice-add 'wttrin-query :after 'render-wttrin-buffer)

@technician77
Copy link

@beacoder
I tried your advice but for some reason there were no colours shown. Then I used brannala's guide and it worked with colours.

@beacoder
Copy link

@beacoder
I tried your advice but for some reason there were no colours shown. Then I used brannala's guide and it worked with colours.

I basicaly used emacs in terminal mode, so failed to see the color.
anyway, good to hear that other guy's solution worked.

@JustPaulD
Copy link

Using emacs 27.1 on Mac
@brannala's recommendation worked.
THANKS!

@etiago
Copy link

etiago commented Dec 21, 2020

I've created a pull request with @brannala 's change: #20

Hopefully one day it can be merged :) and in the meanwhile feel free to use that branch.

@DmHertz
Copy link

DmHertz commented Nov 6, 2023

I setup wttrin as follows:

(use-package wttrin
  :init
  (setq wttrin-default-cities          '("Heidelberg" "Tel-Aviv")
        wttrin-default-accept-language '("Accept-Language" . "en-US")))

I am using GNU Emacs 26.3
...
I am sure I am missing something essential here. Thanks in advance!

Try to customize a bit:
M-x, customize-variable, url-user-agent
write there: curl
Press the button Apply and Save

Or add '(url-user-agent "curl") to your customization file.
Or try to modify your code like this:

(use-package wttrin
  :custom
  (wttrin-default-cities          '("Heidelberg" "Tel-Aviv"))
  (wttrin-default-accept-language '("Accept-Language" . "en-US")
  (url-user-agent                 "curl")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests