From 094f82a7c2c1be0d6ba2e70d9701cf561dfc9399 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Tue, 4 Jan 2011 04:18:06 +0000 Subject: [PATCH] update google weather --- emacs_el/google-weather.el | 11 ++++++++--- emacs_el/org-google-weather.el | 30 +++++++++++++++++------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/emacs_el/google-weather.el b/emacs_el/google-weather.el index 54fe506..be09e34 100644 --- a/emacs_el/google-weather.el +++ b/emacs_el/google-weather.el @@ -38,8 +38,12 @@ "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 @@ -86,7 +90,8 @@ to 0 force a cache renewal." 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)) @@ -99,7 +104,7 @@ to 0 force a cache renewal." (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)))) diff --git a/emacs_el/org-google-weather.el b/emacs_el/org-google-weather.el index 63f601b..ccb4e46 100644 --- a/emacs_el/org-google-weather.el +++ b/emacs_el/org-google-weather.el @@ -37,16 +37,17 @@ (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 @@ -89,6 +90,7 @@ Valid %-sequences are: (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") @@ -101,18 +103,19 @@ Valid %-sequences are: (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 @@ -125,11 +128,12 @@ If LOCATION is not set, use org-google-weather-location." `((?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) -- 2.39.2