X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/590892e2edc0811fb977454f0839dec2a880a8e1..ab3b9137facc977cf39bb407cb1d7763b2e9a449:/packages/metar/metar.el diff --git a/packages/metar/metar.el b/packages/metar/metar.el index 182e8056b..7b78f07f3 100644 --- a/packages/metar/metar.el +++ b/packages/metar/metar.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2007, 2014 Free Software Foundation, Inc. ;; Author: Mario Lang -;; Version: 0 +;; Version: 0.1 ;; Package-Requires: ((cl-lib "0.5")) ;; Keywords: comm @@ -92,39 +92,20 @@ "Variable containing (cached) METAR station information. Use the function `metar-stations' to get the actual station list.") -(defun metar-station-convert-latitude (string) +(defun metar-station-convert-dms-to-deg (string) + "Convert degrees, minutes and optional seconds, to degrees." (when (string-match (rx string-start - (group (1+ digit)) - ?- - (group (1+ digit)) + (group (1+ digit)) ?- (group (1+ digit)) (optional ?- (group (1+ digit))) - (group (char ?N ?S)) + (group (char ?N ?E ?S ?W)) string-end) string) - (funcall (if (string= (match-string 4 string) "N") #'+ #'-) + (funcall (if (memq (aref (match-string 4 string) 0) '(?N ?E)) #'+ #'-) (+ (string-to-number (match-string 1 string)) - (/ (string-to-number (match-string 2 string)) - 60.0) + (/ (string-to-number (match-string 2 string)) 60.0) (if (match-string 3 string) (/ (string-to-number (match-string 3 string)) 3600.0) 0))))) -(defun metar-station-convert-longitude (string) - (when (string-match (rx string-start - (group (1+ digit)) - ?- - (group (1+ digit)) - (optional ?- (group (1+ digit))) - (group (char ?E ?W)) - string-end) string) - (funcall (if (string= (match-string 4 string) "E") #'+ #'-) - (+ (string-to-number (match-string 1 string)) - (/ (string-to-number (match-string 2 string)) - 60.0) - (if (match-string 3 string) - (/ (string-to-number (match-string 3 string)) - 3600.0) - 0))))) - (defun metar-stations () "Retrieve a list of METAR stations. Results are cached in variable `metar-stations'. @@ -147,9 +128,9 @@ If this variable is nil, the information is retrieved from the Internet." (cons 'name (nth 3 item)) (cons 'country (nth 5 item)) (cons 'latitude - (metar-station-convert-latitude (nth 7 item))) + (metar-station-convert-dms-to-deg (nth 7 item))) (cons 'longitude - (metar-station-convert-longitude (nth 8 item))) + (metar-station-convert-dms-to-deg (nth 8 item))) (cons 'altitude (string-to-number (nth 12 item)))))) metar-stations))) (setq data (cdr data))) @@ -564,7 +545,7 @@ Otherwise, determine the best station via latitude/longitude." nil t)))) (let ((info (metar-decode (metar-get-record station)))) (if info - (message "%d minutes ago at %s: %d°%c, %d%% relative humidity%s" + (message "%d minutes ago at %s: %d°%c, %s%d%% humidity, %.1f %S." (/ (truncate (float-time (time-since (cdr (assoc 'timestamp info))))) 60) @@ -574,11 +555,11 @@ Otherwise, determine the best station via latitude/longitude." (cond ((eq (cdr (assq 'temperature metar-units)) 'degC) ?C) ((eq (cdr (assq 'temperature metar-units)) 'degF) ?F)) - (cadr (assoc 'humidity info)) (if (assoc 'phenomena info) - (concat "\n" "Phenomena: " - (cdr (assoc 'phenomena info))) - "")) + (concat (cdr (assoc 'phenomena info)) ", ") + "") + (cadr (assoc 'humidity info)) + (cadr (assoc 'pressure info)) (cddr (assoc 'pressure info))) (message "No weather information found, sorry."))))) (defun metar-station-countries () @@ -638,7 +619,8 @@ Otherwise, determine the best station via latitude/longitude." (format "%.1f°%c" (car dewpoint) (cond ((eq (cdr dewpoint) 'degC) ?C) - ((eq (cdr dewpoint) 'degF) ?F))))) + ((eq (cdr dewpoint) 'degF) ?F) + ((eq (cdr dewpoint) 'degK) ?K))))) (cons ?h (let ((humidity (cdr (assq 'humidity report)))) (format "%d%%" (car humidity))))