Missing . in org-google-weather-icon-alist
[google-weather-el.git] / org-google-weather.el
blob34ad6eba2bad0e2b23e820079ba1e791c16e8287
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>
6 ;; Keywords: comm
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/>.
23 ;;; Commentary:
24 ;; This module allows to display the weather forecast fetched from Google in
25 ;; your Org agenda.
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)
35 ;;; Code:
37 (require 'google-weather)
38 (require 'image)
40 (defgroup org-google-weather nil
41 "Google Weather for Org mode."
42 :group 'comm)
44 ;; Org mode support
45 (defcustom org-google-weather-location
46 "Paris"
47 "Default location for org-google-weather."
48 :group 'org-google-weather)
50 (defcustom org-google-weather-cache-time 43200
51 "Define for how many seconds we should cache the weather."
52 :group 'org-google-weather)
54 (defcustom org-google-weather-display-icon-p t
55 "Display icons."
56 :group 'org-google-weather)
58 (defcustom org-google-weather-icon-directory "/usr/share/icons/gnome/16x16/status"
59 "Directory where to find icon listed in `org-google-weather-icon-alist'."
60 :group 'org-google-weather)
62 (defcustom org-google-weather-icon-alist
63 '((chance_of_rain . "weather-showers-scattered.png")
64 (chance_of_snow . "weather-snow.png")
65 (chance_of_storm . "weather-storm.png")
66 (cloudy . "weather-overcast.png")
67 (dust . "weather-fog.png")
68 (flurries . "weather-storm.png")
69 (fog . "weather-fog.png")
70 (haze . "weather-fog.png")
71 (icy . "weather-snow.png")
72 (mist . "weather-storm.png")
73 (mostly_cloudy . "weather-overcast.png")
74 (mostly_sunny . "weather-clear.png")
75 (partly_cloudy . "weather-few-clouds.png")
76 (rain . "weather-showers.png")
77 (sleet . "weather-snow.png")
78 (smoke . "weather-fog.png")
79 (snow . "weather-snow.png")
80 (storm . "weather-storm.png")
81 (thunderstorm . "weather-storm.png")
82 (sunny . "weather-clear.png"))
83 "Icons to used to illustrate the weather.")
85 (defun org-google-weather (&optional location language)
86 "Return Org entry with the weather for LOCATION in LANGUAGE.
87 If LOCATION is not set, use org-google-weather-location."
88 (let* ((data (google-weather-get-data (or location
89 org-google-weather-location)
90 language
91 org-google-weather-cache-time))
92 (forecast (google-weather-data->forecast-for-date data date)))
93 (when forecast
94 (let ((condition (cadr (assoc 'condition forecast)))
95 (low (cadr (assoc 'low forecast)))
96 (high (cadr (assoc 'high forecast)))
97 ;; But *they* told me it's just about calling functions!
98 (icon (cdr
99 (assoc
100 (intern
101 (file-name-sans-extension
102 (file-name-nondirectory
103 (cadr (assoc 'icon forecast)))))
104 org-google-weather-icon-alist)))
105 (temp-symbol (google-weather-data->temperature-symbol data)))
106 (concat
107 (if org-google-weather-display-icon-p
108 (concat (propertize "icon"
109 'display
110 (create-image
111 (concat org-google-weather-icon-directory "/" icon))
112 'rear-nonsticky '(display))
113 " ")
115 condition ", " low "-" high " " temp-symbol)))))
117 (provide 'org-google-weather)