"Google Weather."
:group 'comm)
+(defcustom google-weather-use-https t
+ "Default protocol to use to access the Google Weather API."
+ :group 'google-weather)
+
(defconst google-weather-url
- "http://www.google.com/ig/api"
+ "www.google.com/ig/api"
"URL of the Google Weather API.")
(defconst google-weather-image-url
data)
(with-current-buffer buffer
(goto-char (point-min))
- (search-forward "\n\n")
+ (unless (search-forward "\n\n" nil t)
+ (error "Data not found"))
(decode-coding-region
(point) (point-max)
(detect-coding-region (point) (point-max) t))
(defun google-weather-build-url (location &optional language)
"Build URL to retrieve weather for LOCATION in LANGUAGE."
- (concat google-weather-url "?weather=" (url-hexify-string location)
+ (concat "http" (when google-weather-use-https "s") "://" google-weather-url "?weather=" (url-hexify-string location)
(when language
(concat "&hl=" language))))
(require 'google-weather)
(require 'image)
(require 'format-spec)
+(require 'solar)
(defgroup org-google-weather nil
"Google Weather for Org mode."
:group 'comm)
-(defcustom org-google-weather-location "Paris"
+(defcustom org-google-weather-location calendar-location-name
"Default location for org-google-weather."
:group 'org-google-weather)
-(defcustom org-google-weather-format "%i %c, %l-%h %s"
+(defcustom org-google-weather-format "%i %c, [%l,%h] %s"
"String to return to describe the weather.
Valid %-sequences are:
- %i the icon
(mostly_sunny . "weather-clear.png")
(partly_cloudy . "weather-few-clouds.png")
(rain . "weather-showers.png")
+ (rain_snow . "weather-snow.png")
(sleet . "weather-snow.png")
(smoke . "weather-fog.png")
(snow . "weather-snow.png")
(defun org-google-weather (&optional location language)
"Return Org entry with the weather for LOCATION in LANGUAGE.
If LOCATION is not set, use org-google-weather-location."
- (let* ((data (google-weather-get-data (or location
- org-google-weather-location)
- language
- org-google-weather-cache-time))
- (forecast (google-weather-data->forecast-for-date data date)))
+ (let* ((data (ignore-errors
+ (google-weather-get-data (or location
+ org-google-weather-location)
+ language
+ org-google-weather-cache-time)))
+ (forecast (when data (google-weather-data->forecast-for-date data date))))
(when forecast
(let ((condition (cadr (assoc 'condition forecast)))
(low (cadr (assoc 'low forecast)))
(high (cadr (assoc 'high forecast)))
(city (google-weather-data->city data))
;; But *they* told me it's just about calling functions!
- (icon (when (window-system)
+ (icon (when window-system
(cdr
(assoc
(intern
`((?i . ,(if (and icon org-google-weather-display-icon-p)
(propertize "icon"
'display
- (create-image
- (concat
- org-google-weather-icon-directory
- "/"
- icon))
+ (append
+ (create-image
+ (concat
+ org-google-weather-icon-directory
+ "/"
+ icon)) '(:ascent center))
'rear-nonsticky '(display))
""))
(?c . ,condition)