Add Japanese and Chinese icons
[google-weather-el.git] / org-google-weather.el
blob402c0a9c8a8e36bc2a991edce2ef8bed680fb64a
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)
41 (defgroup org-google-weather nil
42 "Google Weather for Org mode."
43 :group 'comm)
45 (defcustom org-google-weather-location "Paris"
46 "Default location for org-google-weather."
47 :group 'org-google-weather)
49 (defcustom org-google-weather-format "%i %c, %l-%h %s"
50 "String to return to describe the weather.
51 Valid %-sequences are:
52 - %i the icon
53 - %c means the weather condition
54 - %L the supplied location
55 - %C the city the weather is for
56 - %l the lower temperature
57 - %h the higher temperature
58 - %s the temperature unit symbol")
60 (defcustom org-google-weather-cache-time 43200
61 "Define for how many seconds we should cache the weather."
62 :group 'org-google-weather)
64 (defcustom org-google-weather-display-icon-p t
65 "Display icons."
66 :group 'org-google-weather)
68 (defcustom org-google-weather-icon-directory "/usr/share/icons/gnome/16x16/status"
69 "Directory where to find icon listed in `org-google-weather-icon-alist'."
70 :group 'org-google-weather)
72 (defcustom org-google-weather-icon-alist
73 '((chance_of_rain . "weather-showers-scattered.png")
74 (chance_of_snow . "weather-snow.png")
75 (chance_of_storm . "weather-storm.png")
76 (cn_cloudy . "weather-overcast.png")
77 (cn_heavyrun . "weather-showers.png")
78 (cn_sunny . "weather-clear.png")
79 (cloudy . "weather-overcast.png")
80 (dust . "weather-fog.png")
81 (flurries . "weather-storm.png")
82 (fog . "weather-fog.png")
83 (haze . "weather-fog.png")
84 (icy . "weather-snow.png")
85 (jp_sunny . "weather-clear.png")
86 (jp_cloudy . "weather-overcast.png")
87 (mist . "weather-storm.png")
88 (mostly_cloudy . "weather-overcast.png")
89 (mostly_sunny . "weather-clear.png")
90 (partly_cloudy . "weather-few-clouds.png")
91 (rain . "weather-showers.png")
92 (sleet . "weather-snow.png")
93 (smoke . "weather-fog.png")
94 (snow . "weather-snow.png")
95 (storm . "weather-storm.png")
96 (thunderstorm . "weather-storm.png")
97 (sunny . "weather-clear.png"))
98 "Icons to used to illustrate the weather.")
100 ;;;###autoload
101 (defun org-google-weather (&optional location language)
102 "Return Org entry with the weather for LOCATION in LANGUAGE.
103 If LOCATION is not set, use org-google-weather-location."
104 (let* ((data (google-weather-get-data (or location
105 org-google-weather-location)
106 language
107 org-google-weather-cache-time))
108 (forecast (google-weather-data->forecast-for-date data date)))
109 (when forecast
110 (let ((condition (cadr (assoc 'condition forecast)))
111 (low (cadr (assoc 'low forecast)))
112 (high (cadr (assoc 'high forecast)))
113 (city (google-weather-data->city data))
114 ;; But *they* told me it's just about calling functions!
115 (icon (cdr
116 (assoc
117 (intern
118 (file-name-sans-extension
119 (file-name-nondirectory
120 (cadr (assoc 'icon forecast)))))
121 org-google-weather-icon-alist)))
122 (temp-symbol (google-weather-data->temperature-symbol data)))
123 (format-spec org-google-weather-format
124 `((?i . ,(if org-google-weather-display-icon-p
125 (concat (propertize "icon"
126 'display
127 (create-image
128 (concat
129 org-google-weather-icon-directory
131 icon))
132 'rear-nonsticky '(display))
133 " ")
134 ""))
135 (?c . ,condition)
136 (?L . ,location)
137 (?C . ,city)
138 (?l . ,low)
139 (?h . ,high)
140 (?s . ,temp-symbol)))))))
142 (provide 'org-google-weather)