diff --git a/README.org b/README.org index 4df0a48..d0f0bf4 100644 --- a/README.org +++ b/README.org @@ -20,10 +20,16 @@ To access the WAQI project API it’s necessary to register at http://aqicn.org/ aqi-use-cache t) #+END_SRC -The simplest way to view AQI info is with =M-x aqi-report= which displays air quality info for your algorithmically derived location (equivalent to the location ="here"=) or the name of a place. A place can be the name of a city (in which case the nearest monitoring station is used) or the name of specific monitoring station. +The simplest way to view AQI info is with =M-x aqi-report= which displays air quality info for your algorithmically derived location (equivalent to the location "here") or the name of a place. A place can be the name of a city (in which case the nearest monitoring station is used) or the id of specific monitoring station. +By name… #+BEGIN_SRC emacs-lisp -(aqi-report "Taipei") +(aqi-report "Ulaanbaatar") +#+END_SRC + +By id… +#+BEGIN_SRC emacs-lisp +(aqi-report "@7397") #+END_SRC A detailed report is displayed by default and a single line summary can be provided by using the keyword ='brief= diff --git a/aqi.el b/aqi.el index bda8a4e..e0148cb 100644 --- a/aqi.el +++ b/aqi.el @@ -158,6 +158,21 @@ (aqi--city-cache-get city) (aqi-request city))) +(defun aqi-search (name) + "Search for the nearest stations (if any) matching a given NAME." + (request + (format "https://api.waqi.info/search/?keyword=%s&" name) + :sync t + :params `(("token" . ,aqi-api-key)) + :parser 'json-read + :success (cl-function + (lambda (&key data &allow-other-keys) + (pcase (assoc-default 'status data) + ("ok" (message "Search: %s" (assoc-default 'data data))) + ("error" (message "Search error: %s" (assoc-default 'data data)))))) + :error (cl-function + (lambda (&rest args &key error-thrown &allow-other-keys) + (message "WAQI error: %s" error-thrown))))) ;; printing, formatting and presenting.