bcbcarl / emacs-wttrin

Emacs frontend for weather web service wttr.in.
MIT License
148 stars 40 forks source link

Raw html instad of wttrin #16

Open hummuscience opened 4 years ago

hummuscience commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

This does not fix it for me.

emacle commented 4 years ago

@SodaLover https://github.com/bcbcarl/emacs-wttrin/pull/17/commits/ed569277e0cfa5e5c1534a5ea2b404dec2ef0183

(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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

I followed @brannala's recommendation and it worked!

beacoder commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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

etiago commented 3 years ago

I've created a pull request with @brannala 's change: https://github.com/bcbcarl/emacs-wttrin/pull/20

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

DmHertz commented 11 months ago

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")))