emacs-wttrin icon indicating copy to clipboard operation
emacs-wttrin copied to clipboard

Raw html instad of wttrin

Open hummuscience opened this issue 4 years ago • 12 comments

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!

hummuscience avatar May 04 '20 08:05 hummuscience

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

emacle avatar May 06 '20 06:05 emacle

This does not fix it for me.

SodaLover avatar May 07 '20 20:05 SodaLover

@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

emacle avatar May 11 '20 02:05 emacle

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!

dagst47 avatar May 28 '20 16:05 dagst47

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

brannala avatar Jul 15 '20 20:07 brannala

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

I followed @brannala's recommendation and it worked!

MooersLab avatar Jul 15 '20 20:07 MooersLab

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)

beacoder avatar Jul 28 '20 10:07 beacoder

@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.

technician77 avatar Jul 31 '20 02:07 technician77

@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.

beacoder avatar Jul 31 '20 03:07 beacoder

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

JustPaulD avatar Sep 26 '20 20:09 JustPaulD

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.

etiago avatar Dec 21 '20 13:12 etiago

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

DmHertz avatar Nov 06 '23 03:11 DmHertz