]> git.donarmstrong.com Git - lib.git/commitdiff
update google weather
authorDon Armstrong <don@donarmstrong.com>
Tue, 4 Jan 2011 04:18:06 +0000 (04:18 +0000)
committerDon Armstrong <don@donarmstrong.com>
Tue, 4 Jan 2011 04:18:06 +0000 (04:18 +0000)
emacs_el/google-weather.el
emacs_el/org-google-weather.el

index 54fe506df4f4ea1913b4637218e8a420774c8751..be09e34cc4ed2a92d13fce8ee9ac4056cbc29814 100644 (file)
   "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))))
 
index 63f601bf786e6ac9ff3b9abc4dc6d9a2e212dadc..ccb4e46e1b4fae888c6ef08979f1fbc37af60280 100644 (file)
 (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)