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."
46 (defcustom org-google-weather-location calendar-location-name
47 "Default location for org-google-weather."
48 :group
'org-google-weather
)
50 (defcustom org-google-weather-format
"%i %c, %l-%h %s"
51 "String to return to describe the weather.
52 Valid %-sequences are:
54 - %c means the weather condition
55 - %L the supplied location
56 - %C the city the weather is for
57 - %l the lower temperature
58 - %h the higher temperature
59 - %s the temperature unit symbol")
61 (defcustom org-google-weather-cache-time
43200
62 "Define for how many seconds we should cache the weather."
63 :group
'org-google-weather
)
65 (defcustom org-google-weather-display-icon-p t
67 :group
'org-google-weather
)
69 (defcustom org-google-weather-icon-directory
"/usr/share/icons/gnome/16x16/status"
70 "Directory where to find icon listed in `org-google-weather-icon-alist'."
71 :group
'org-google-weather
)
73 (defcustom org-google-weather-icon-alist
74 '((chance_of_rain .
"weather-showers-scattered.png")
75 (chance_of_snow .
"weather-snow.png")
76 (chance_of_storm .
"weather-storm.png")
77 (cn_cloudy .
"weather-overcast.png")
78 (cn_heavyrun .
"weather-showers.png")
79 (cn_sunny .
"weather-clear.png")
80 (cloudy .
"weather-overcast.png")
81 (dust .
"weather-fog.png")
82 (flurries .
"weather-storm.png")
83 (fog .
"weather-fog.png")
84 (haze .
"weather-fog.png")
85 (icy .
"weather-snow.png")
86 (jp_sunny .
"weather-clear.png")
87 (jp_cloudy .
"weather-overcast.png")
88 (mist .
"weather-storm.png")
89 (mostly_cloudy .
"weather-overcast.png")
90 (mostly_sunny .
"weather-clear.png")
91 (partly_cloudy .
"weather-few-clouds.png")
92 (rain .
"weather-showers.png")
93 (sleet .
"weather-snow.png")
94 (smoke .
"weather-fog.png")
95 (snow .
"weather-snow.png")
96 (storm .
"weather-storm.png")
97 (thunderstorm .
"weather-storm.png")
98 (sunny .
"weather-clear.png"))
99 "Icons to use to illustrate the weather.")
102 (defun org-google-weather (&optional location language
)
103 "Return Org entry with the weather for LOCATION in LANGUAGE.
104 If LOCATION is not set, use org-google-weather-location."
105 (let* ((data (ignore-errors
106 (google-weather-get-data (or location
107 org-google-weather-location
)
109 org-google-weather-cache-time
)))
110 (forecast (when data
(google-weather-data->forecast-for-date data date
))))
112 (let ((condition (cadr (assoc 'condition forecast
)))
113 (low (cadr (assoc 'low forecast
)))
114 (high (cadr (assoc 'high forecast
)))
115 (city (google-weather-data->city data
))
116 ;; But *they* told me it's just about calling functions!
117 (icon (when window-system
121 (file-name-sans-extension
122 (file-name-nondirectory
123 (cadr (assoc 'icon forecast
)))))
124 org-google-weather-icon-alist
))))
125 (temp-symbol (google-weather-data->temperature-symbol data
)))
126 (format-spec org-google-weather-format
127 `((?i .
,(if (and icon org-google-weather-display-icon-p
)
133 org-google-weather-icon-directory
135 icon
)) '(:ascent center
))
136 'rear-nonsticky
'(display))
143 (?s .
,temp-symbol
)))))))
145 (provide 'org-google-weather
)