1 ;;; org-google-weather.el --- Show Google Weather forecasts in Org agenda.
3 ;; Copyright (C) 2010 Julien Danjou
5 ;; Author: Julien Danjou <julien@danjou.info>
8 ;; This file is NOT part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; This module allows to display the weather forecast fetched from Google in
27 ;; Wednesday 8 September 2010
28 ;; Weather: Pluie, 12/18 ℃
29 ;; Thursday 9 September 2010
30 ;; Weather: Couverture nuageuse partielle, 11/21 ℃
32 ;; Just add the following in an Org buffer:
33 ;; %%(org-google-weather)
37 (require 'google-weather
)
39 (require 'format-spec
)
42 (defgroup org-google-weather nil
43 "Google Weather for Org mode."
47 (defcustom org-google-weather-location calendar-location-name
48 "Default location for org-google-weather."
49 :group
'org-google-weather
)
51 (defcustom org-google-weather-format
"%i %c, [%l,%h] %s"
52 "String to return to describe the weather.
53 Valid %-sequences are:
55 - %c means the weather condition
56 - %L the supplied location
57 - %C the city the weather is for
58 - %l the lower temperature
59 - %h the higher temperature
60 - %s the temperature unit symbol")
62 (defcustom org-google-weather-cache-time
43200
63 "Define for how many seconds we should cache the weather."
64 :group
'org-google-weather
)
66 (defcustom org-google-weather-display-icon-p t
68 :group
'org-google-weather
)
70 (defun org-google-weather-get-icon (url)
72 (google-weather-retrieve-data-raw url org-google-weather-cache-time
)
73 (unless (search-forward "\n\n" nil t
)
74 (error "Data not found"))
75 (let ((data (buffer-substring (point) (point-max))))
76 (kill-buffer (current-buffer))
80 (defun org-google-weather (&optional location language
)
81 "Return Org entry with the weather for LOCATION in LANGUAGE.
82 If LOCATION is not set, use org-google-weather-location."
83 (let* ((location (or location org-google-weather-location
))
85 (google-weather-get-data location
87 org-google-weather-cache-time
)))
88 (problem-cause (when data
(google-weather-data->problem-cause data
)))
89 (forecast (when (and (null problem-cause
) data
)
90 (google-weather-data->forecast-for-date data date
))))
92 (message "%s: %s" location problem-cause
)
94 (let ((condition (cadr (assoc 'condition forecast
)))
95 (low (cadr (assoc 'low forecast
)))
96 (high (cadr (assoc 'high forecast
)))
97 (city (google-weather-data->city data
))
98 ;; But *they* told me it's just about calling functions!
99 (icon (when (display-images-p)
100 (create-image (org-google-weather-get-icon
101 (cadr (assoc 'icon forecast
)))
103 (temp-symbol (google-weather-data->temperature-symbol data
)))
104 (format-spec org-google-weather-format
105 `((?i .
,(if (and icon org-google-weather-display-icon-p
)
111 'rear-nonsticky
'(display))
118 (?s .
,temp-symbol
))))))))
120 (provide 'org-google-weather
)