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 (rain_snow . "weather-snow.png")
94 (sleet . "weather-snow.png")
95 (smoke . "weather-fog.png")
96 (snow . "weather-snow.png")
97 (storm . "weather-storm.png")
98 (thunderstorm . "weather-storm.png")
99 (sunny . "weather-clear.png"))
100 "Icons to use to illustrate the weather.")
103 (defun org-google-weather (&optional location language)
104 "Return Org entry with the weather for LOCATION in LANGUAGE.
105 If LOCATION is not set, use org-google-weather-location."
106 (let* ((data (ignore-errors
107 (google-weather-get-data (or location
108 org-google-weather-location)
110 org-google-weather-cache-time)))
111 (forecast (when data (google-weather-data->forecast-for-date data date))))
113 (let ((condition (cadr (assoc 'condition forecast)))
114 (low (cadr (assoc 'low forecast)))
115 (high (cadr (assoc 'high forecast)))
116 (city (google-weather-data->city data))
117 ;; But *they* told me it's just about calling functions!
118 (icon (when window-system
122 (file-name-sans-extension
123 (file-name-nondirectory
124 (cadr (assoc 'icon forecast)))))
125 org-google-weather-icon-alist))))
126 (temp-symbol (google-weather-data->temperature-symbol data)))
127 (format-spec org-google-weather-format
128 `((?i . ,(if (and icon org-google-weather-display-icon-p)
134 org-google-weather-icon-directory
136 icon)) '(:ascent center))
137 'rear-nonsticky '(display))
144 (?s . ,temp-symbol)))))))
146 (provide 'org-google-weather)