emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [OT] Icon problem with org-google-weather
@ 2011-06-06  0:27 Nick Dokos
  2011-06-06  7:38 ` Tassilo Horn
  2011-06-07  4:53 ` Nick Dokos
  0 siblings, 2 replies; 7+ messages in thread
From: Nick Dokos @ 2011-06-06  0:27 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: nicholas.dokos

This is off-topic but it is driving me bananas. I do

--8<---------------cut here---------------start------------->8---
(setq date '(6 5 2011))
(6 5 2011)
(setq foo (let ((org-google-weather-cache-time 0))
      (org-google-weather)))
(setq bar (org-google-weather))
(equal foo bar)
(insert foo)
(insert bar)
--8<---------------cut here---------------end--------------->8---

in the *scratch* buffer. The idea is that foo is freshly obtained from
google every time: it never goes to cached data since the cache time is
set to 0. bar, otoh, is obtained from cache.  I've traced the code and
that's indeed what happens.  The two strings compare equal: (equal foo bar)
returns t - just in case, I also displayed them in separate windows and
did a compare-windows: they are the same that way too.

Nevertheless, when I insert foo, the icon is shown, but when I insert
bar, the icon is an empty box. What am I missing?

Thanks,
Nick

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [OT] Icon problem with org-google-weather
  2011-06-06  0:27 [OT] Icon problem with org-google-weather Nick Dokos
@ 2011-06-06  7:38 ` Tassilo Horn
  2011-06-06 13:51   ` Nick Dokos
  2011-06-07  4:53 ` Nick Dokos
  1 sibling, 1 reply; 7+ messages in thread
From: Tassilo Horn @ 2011-06-06  7:38 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> writes:

> This is off-topic but it is driving me bananas. I do
>
> (setq date '(6 5 2011))
> (6 5 2011)
> (setq foo (let ((org-google-weather-cache-time 0))
>       (org-google-weather)))
> (setq bar (org-google-weather))
> (equal foo bar)
> (insert foo)
> (insert bar)
>
> in the *scratch* buffer. The idea is that foo is freshly obtained from
> google every time: it never goes to cached data since the cache time
> is set to 0. bar, otoh, is obtained from cache.  I've traced the code
> and that's indeed what happens.  The two strings compare equal: (equal
> foo bar) returns t - just in case, I also displayed them in separate
> windows and did a compare-windows: they are the same that way too.
>
> Nevertheless, when I insert foo, the icon is shown, but when I insert
> bar, the icon is an empty box. What am I missing?

I have a similar problem.  In one of my org files, I have

  %%(org-google-weather "Montabaur" "de")

and since lately, I get only squares.

That said, while trying your example, `org-google-weather' always
returned nil.  The reason is that I don't have
`org-google-weather-location' set explicitly to something different as
the default value.  But that default is a form and it is never evaluated
AFAICS.  So that seems to be another bug.

Ok, so when I change your testcase to this...

--8<---------------cut here---------------start------------->8---
(defun foobar ()
  (interactive)
  (let ((date '(6 6 2011)))
    (setq bar (org-google-weather "Montabaur" "DE"))
    (setq foo (let ((org-google-weather-cache-time 0))
		(org-google-weather "Montabaur" "DE")))
    (string= foo bar)
    (insert foo)
    (insert bar)))
--8<---------------cut here---------------end--------------->8---

I get an error at the foo value evaluation.  The evaluation of bar seems
to work fine...

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (error "Data not found")
  signal(error ("Data not found"))
  error("Data not found")
  (if (search-forward "\n\n" nil t) nil (error "Data not found"))
  (unless (search-forward "\n\n" nil t) (error "Data not found"))
  (save-current-buffer (set-buffer (google-weather-retrieve-data-raw url org-google-weather-cache-time)) (unless (search-forward "\n\n" nil t) (error "Data not found")) (let ((data (buffer-substring (point) (point-max)))) (kill-buffer (current-buffer)) data))
  (with-current-buffer (google-weather-retrieve-data-raw url org-google-weather-cache-time) (unless (search-forward "\n\n" nil t) (error "Data not found")) (let ((data (buffer-substring (point) (point-max)))) (kill-buffer (current-buffer)) data))
  org-google-weather-get-icon("http://g0.gstatic.com/images/icons/onebox/weather_scatteredthunderstorms-40.gif")
  (create-image (org-google-weather-get-icon (cadr (assoc (quote icon) forecast))) nil t)
  (progn (create-image (org-google-weather-get-icon (cadr (assoc (quote icon) forecast))) nil t))
  (if (display-images-p) (progn (create-image (org-google-weather-get-icon (cadr (assoc (quote icon) forecast))) nil t)))
  (when (display-images-p) (create-image (org-google-weather-get-icon (cadr (assoc (quote icon) forecast))) nil t))
  (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon (cadr (assoc ... forecast))) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if (and icon org-google-weather-display-icon-p) (propertize "icon" (quote display) (append icon ...) (quote rear-nonsticky) (quote ...)) "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol)))))
  (progn (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon (cadr ...)) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if (and icon org-google-weather-display-icon-p) (propertize "icon" ... ... ... ...) "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol))))))
  (if forecast (progn (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon ...) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if ... ... "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol)))))))
  (when forecast (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon (cadr ...)) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if (and icon org-google-weather-display-icon-p) (propertize "icon" ... ... ... ...) "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol))))))
  (if problem-cause (message "%s: %s" location problem-cause) (when forecast (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon ...) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if ... ... "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol)))))))
  (let* ((location (or location org-google-weather-location)) (data (ignore-errors (google-weather-get-data location language org-google-weather-cache-time))) (problem-cause (when data (google-weather-data->problem-cause data))) (forecast (when (and (null problem-cause) data) (google-weather-data->forecast-for-date data date)))) (if problem-cause (message "%s: %s" location problem-cause) (when forecast (let ((condition (cadr (assoc ... forecast))) (low (cadr (assoc ... forecast))) (high (cadr (assoc ... forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image ... nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, ...) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (
 104 \, high) (115 \, temp-symbol))))))))
  org-google-weather("Montabaur" "DE")
  (let ((org-google-weather-cache-time 0)) (org-google-weather "Montabaur" "DE"))
  (setq foo (let ((org-google-weather-cache-time 0)) (org-google-weather "Montabaur" "DE")))
  (let ((date (quote (6 6 2011)))) (setq foo (let ((org-google-weather-cache-time 0)) (org-google-weather "Montabaur" "DE"))) (setq bar (org-google-weather "Montabaur" "DE")) (string= foo bar) (insert foo) (insert bar))
  eval((let ((date (quote (6 6 2011)))) (setq foo (let ((org-google-weather-cache-time 0)) (org-google-weather "Montabaur" "DE"))) (setq bar (org-google-weather "Montabaur" "DE")) (string= foo bar) (insert foo) (insert bar)) nil)
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [OT] Icon problem with org-google-weather
  2011-06-06  7:38 ` Tassilo Horn
@ 2011-06-06 13:51   ` Nick Dokos
  2011-06-06 15:27     ` Tassilo Horn
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Dokos @ 2011-06-06 13:51 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: nicholas.dokos, emacs-orgmode

Tassilo Horn <tassilo@member.fsf.org> wrote:

> > Nevertheless, when I insert foo, the icon is shown, but when I insert
> > bar, the icon is an empty box. What am I missing?
> 
> I have a similar problem.  In one of my org files, I have
> 
>   %%(org-google-weather "Montabaur" "de")
> 
> and since lately, I get only squares.
> 
> That said, while trying your example, `org-google-weather' always
> returned nil.  The reason is that I don't have
> `org-google-weather-location' set explicitly to something different as
> the default value.  But that default is a form and it is never evaluated
> AFAICS.  So that seems to be another bug.
> 
> Ok, so when I change your testcase to this...
> 
> --8<---------------cut here---------------start------------->8---
> (defun foobar ()
>   (interactive)
>   (let ((date '(6 6 2011)))
>     (setq bar (org-google-weather "Montabaur" "DE"))
>     (setq foo (let ((org-google-weather-cache-time 0))
> 		(org-google-weather "Montabaur" "DE")))
>     (string= foo bar)
>     (insert foo)
>     (insert bar)))
> --8<---------------cut here---------------end--------------->8---
> 
> I get an error at the foo value evaluation.  The evaluation of bar seems
> to work fine...
> 
> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (error "Data not found")

Yes, the "Data not found" problem is an org-google-weather problem,

I sent Julien the following patch - either apply it by hand or
check Julien's git repo: it may be there already.

--8<---------------cut here---------------start------------->8---
diff --git a/org-google-weather.el b/org-google-weather.el
index 3ff0aa3..02db878 100644
--- a/org-google-weather.el
+++ b/org-google-weather.el
@@ -70,6 +70,7 @@ Valid %-sequences are:
 (defun org-google-weather-get-icon (url)
   (with-current-buffer
       (google-weather-retrieve-data-raw url org-google-weather-cache-time)
+    (goto-char (point-min))
     (unless (search-forward "\n\n" nil t)
       (error "Data not found"))
     (let ((data (buffer-substring (point) (point-max))))
--8<---------------cut here---------------end--------------->8---

Nick

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [OT] Icon problem with org-google-weather
  2011-06-06 13:51   ` Nick Dokos
@ 2011-06-06 15:27     ` Tassilo Horn
  2011-06-06 15:40       ` Nick Dokos
  0 siblings, 1 reply; 7+ messages in thread
From: Tassilo Horn @ 2011-06-06 15:27 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> writes:

>> --8<---------------cut here---------------start------------->8---
>> (defun foobar ()
>>   (interactive)
>>   (let ((date '(6 6 2011)))
>>     (setq bar (org-google-weather "Montabaur" "DE"))
>>     (setq foo (let ((org-google-weather-cache-time 0))
>> 		(org-google-weather "Montabaur" "DE")))
>>     (string= foo bar)
>>     (insert foo)
>>     (insert bar)))
>> --8<---------------cut here---------------end--------------->8---
>> 
>> I get an error at the foo value evaluation.  The evaluation of bar seems
>> to work fine...
>> 
>> --8<---------------cut here---------------start------------->8---
>> Debugger entered--Lisp error: (error "Data not found")
>
> Yes, the "Data not found" problem is an org-google-weather problem,
>
> I sent Julien the following patch - either apply it by hand or
> check Julien's git repo: it may be there already.

It's already there.  But now I get

  (error "Bad url: :/ig/images/weather/chance_of_storm.gif")

in the first `org-google-weather' call.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [OT] Icon problem with org-google-weather
  2011-06-06 15:27     ` Tassilo Horn
@ 2011-06-06 15:40       ` Nick Dokos
  2011-06-06 16:35         ` Nick Dokos
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Dokos @ 2011-06-06 15:40 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: nicholas.dokos, emacs-orgmode

Tassilo Horn <tassilo@member.fsf.org> wrote:

> Nick Dokos <nicholas.dokos@hp.com> writes:
> 
> >> --8<---------------cut here---------------start------------->8---
> >> (defun foobar ()
> >>   (interactive)
> >>   (let ((date '(6 6 2011)))
> >>     (setq bar (org-google-weather "Montabaur" "DE"))
> >>     (setq foo (let ((org-google-weather-cache-time 0))
> >> 		(org-google-weather "Montabaur" "DE")))
> >>     (string= foo bar)
> >>     (insert foo)
> >>     (insert bar)))
> >> --8<---------------cut here---------------end--------------->8---
> >> 
> >> I get an error at the foo value evaluation.  The evaluation of bar seems
> >> to work fine...
> >> 
> >> --8<---------------cut here---------------start------------->8---
> >> Debugger entered--Lisp error: (error "Data not found")
> >
> > Yes, the "Data not found" problem is an org-google-weather problem,
> >
> > I sent Julien the following patch - either apply it by hand or
> > check Julien's git repo: it may be there already.
> 
> It's already there.  But now I get
> 
>   (error "Bad url: :/ig/images/weather/chance_of_storm.gif")
> 
> in the first `org-google-weather' call.
> 

Me too: this is recent - the image URLs were of the form g0.static (or
something like this) yesterday - but it seems that Google is playing games:

when I visit https://www.google.com/ig/api?weather=Boston through a browser,
I get <icon data="/ig/images/weather/partly_cloudy.gif"/> in the returned XML.

Nick

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [OT] Icon problem with org-google-weather
  2011-06-06 15:40       ` Nick Dokos
@ 2011-06-06 16:35         ` Nick Dokos
  0 siblings, 0 replies; 7+ messages in thread
From: Nick Dokos @ 2011-06-06 16:35 UTC (permalink / raw)
  Cc: Tassilo Horn, nicholas.dokos, emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> wrote:

> Tassilo Horn <tassilo@member.fsf.org> wrote:
> > It's already there.  But now I get
> > 
> >   (error "Bad url: :/ig/images/weather/chance_of_storm.gif")
> > 
> > in the first `org-google-weather' call.
> > 
> 
> Me too: this is recent - the image URLs were of the form g0.static (or
> something like this) yesterday - but it seems that Google is playing games:
> 
> when I visit https://www.google.com/ig/api?weather=Boston through a browser,
> I get <icon data="/ig/images/weather/partly_cloudy.gif"/> in the returned XML.
> 

Here's a quick-and-dirty hack to work around Google's inability to make
up its mind about what it will return: a path or a complete URL? The
hack assumes that the value-du-jour is a path, so if tomorrow Google changes
its mind, you may have to revert:

diff --git a/google-weather.el b/google-weather.el
index fad9ed7..f59b1bf 100644
--- a/google-weather.el
+++ b/google-weather.el
@@ -172,7 +172,7 @@ See `google-weather-retrieve-data' for the use of EXPIRE-TIME."
          `(,forecast-encoded-date
            (low ,(google-weather-assoc 'low forecast))
            (high ,(google-weather-assoc 'high forecast))
-           (icon ,(google-weather-assoc 'icon forecast))
+           (icon ,(concat "https://www.google.com" (google-weather-assoc 'icon forecast)))
            (condition ,(google-weather-assoc 'condition forecast)))))
      (loop for entry in (google-weather-data->weather data)
            when (eq (car entry) 'forecast_conditions)

With this, I get the usual 4-day org-google-weather forecast in my agenda,
except that cached images still don't work.

Nick

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [OT] Icon problem with org-google-weather
  2011-06-06  0:27 [OT] Icon problem with org-google-weather Nick Dokos
  2011-06-06  7:38 ` Tassilo Horn
@ 2011-06-07  4:53 ` Nick Dokos
  1 sibling, 0 replies; 7+ messages in thread
From: Nick Dokos @ 2011-06-07  4:53 UTC (permalink / raw)
  Cc: nicholas.dokos, emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> wrote:

> This is off-topic but it is driving me bananas. I do
> 
> (setq date '(6 5 2011))
> (6 5 2011)
> (setq foo (let ((org-google-weather-cache-time 0))
>       (org-google-weather)))
> (setq bar (org-google-weather))
> (equal foo bar)
> (insert foo)
> (insert bar)
> 
> in the *scratch* buffer. The idea is that foo is freshly obtained from
> google every time: it never goes to cached data since the cache time is
> set to 0. bar, otoh, is obtained from cache.  I've traced the code and
> that's indeed what happens.  The two strings compare equal: (equal foo bar)
> returns t - just in case, I also displayed them in separate windows and
> did a compare-windows: they are the same that way too.
> 
> Nevertheless, when I insert foo, the icon is shown, but when I insert
> bar, the icon is an empty box. What am I missing?
> 

It turns out that they *are* different after all: you can't see it in
text form, but when the cached file is read, I think some of the bytes get
combined into multibyte characters. It finally became visible when
I did string-to-list on the image data. Here is the patch to url-cache.el
that I'm running with currently - it seems to resolve the problem:

--8<---------------cut here---------------start------------->8---
diff -u ~/src/emacs/emacs.repo/emacs/lisp/url/url-cache.el url-cache.el
--- /home/nick/src/emacs/emacs.repo/emacs/lisp/url/url-cache.el	2011-03-14 10:54:14.596645931 -0400
+++ url-cache.el	2011-06-07 00:30:35.082826000 -0400
@@ -191,6 +191,7 @@
 ;;;###autoload
 (defun url-cache-extract (fnam)
   "Extract FNAM from the local disk cache."
+  (set-buffer-multibyte nil)
   (erase-buffer)
   (insert-file-contents-literally fnam))
 
--8<---------------cut here---------------end--------------->8---

Can somebody who knows about these things give a thumbs-up or -down on
this change? If thumbs-down, how should it be fixed?

Thanks,
Nick

PS I must say this was no fun at all.
PPS  I posted the original question and this result to the emacs list as well.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-06-07  4:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-06  0:27 [OT] Icon problem with org-google-weather Nick Dokos
2011-06-06  7:38 ` Tassilo Horn
2011-06-06 13:51   ` Nick Dokos
2011-06-06 15:27     ` Tassilo Horn
2011-06-06 15:40       ` Nick Dokos
2011-06-06 16:35         ` Nick Dokos
2011-06-07  4:53 ` Nick Dokos

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).