Add org-google-weather group to org group
[google-weather-el.git] / org-google-weather.el
blobc1c8a92d50b58cc6f3a57387432f917a08ea8f6e
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)
39 (require 'format-spec)
40 (require 'solar)
42 (defgroup org-google-weather nil
43 "Google Weather for Org mode."
44 :group 'comm
45 :group 'org)
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:
54 - %i the icon
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
67 "Display icons."
68 :group 'org-google-weather)
70 (defcustom org-google-weather-icon-directory "/usr/share/icons/gnome/16x16/status"
71 "Directory where to find icon listed in `org-google-weather-icon-alist'."
72 :group 'org-google-weather)
74 (defcustom org-google-weather-icon-alist
75 '((chance_of_rain . "weather-showers-scattered.png")
76 (chance_of_snow . "weather-snow.png")
77 (chance_of_storm . "weather-storm.png")
78 (cn_cloudy . "weather-overcast.png")
79 (cn_heavyrun . "weather-showers.png")
80 (cn_sunny . "weather-clear.png")
81 (cloudy . "weather-overcast.png")
82 (dust . "weather-fog.png")
83 (flurries . "weather-storm.png")
84 (fog . "weather-fog.png")
85 (haze . "weather-fog.png")
86 (icy . "weather-snow.png")
87 (jp_sunny . "weather-clear.png")
88 (jp_cloudy . "weather-overcast.png")
89 (mist . "weather-storm.png")
90 (mostly_cloudy . "weather-overcast.png")
91 (mostly_sunny . "weather-clear.png")
92 (partly_cloudy . "weather-few-clouds.png")
93 (rain . "weather-showers.png")
94 (rain_snow . "weather-snow.png")
95 (sleet . "weather-snow.png")
96 (smoke . "weather-fog.png")
97 (snow . "weather-snow.png")
98 (storm . "weather-storm.png")
99 (thunderstorm . "weather-storm.png")
100 (sunny . "weather-clear.png"))
101 "Icons to use to illustrate the weather.")
103 ;;;###autoload
104 (defun org-google-weather (&optional location language)
105 "Return Org entry with the weather for LOCATION in LANGUAGE.
106 If LOCATION is not set, use org-google-weather-location."
107 (let* ((data (ignore-errors
108 (google-weather-get-data (or location
109 org-google-weather-location)
110 language
111 org-google-weather-cache-time)))
112 (forecast (when data (google-weather-data->forecast-for-date data date))))
113 (when forecast
114 (let ((condition (cadr (assoc 'condition forecast)))
115 (low (cadr (assoc 'low forecast)))
116 (high (cadr (assoc 'high forecast)))
117 (city (google-weather-data->city data))
118 ;; But *they* told me it's just about calling functions!
119 (icon (when window-system
120 (cdr
121 (assoc
122 (intern
123 (file-name-sans-extension
124 (file-name-nondirectory
125 (cadr (assoc 'icon forecast)))))
126 org-google-weather-icon-alist))))
127 (temp-symbol (google-weather-data->temperature-symbol data)))
128 (format-spec org-google-weather-format
129 `((?i . ,(if (and icon org-google-weather-display-icon-p)
130 (propertize "icon"
131 'display
132 (append
133 (create-image
134 (concat
135 org-google-weather-icon-directory
137 icon)) '(:ascent center))
138 'rear-nonsticky '(display))
139 ""))
140 (?c . ,condition)
141 (?L . ,location)
142 (?C . ,city)
143 (?l . ,low)
144 (?h . ,high)
145 (?s . ,temp-symbol)))))))
147 (provide 'org-google-weather)