]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
weather plugin: properly support and signal multiple weather stations when one has...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 26 Mar 2008 21:17:18 +0000 (22:17 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 26 Mar 2008 21:17:18 +0000 (22:17 +0100)
data/rbot/plugins/weather.rb

index b58354471e302101fe349c51d4b5622b2dc3f100..ff5f053757562e5c9db84f031c89860265b83b4b 100644 (file)
@@ -226,13 +226,20 @@ class WeatherPlugin < Plugin
   end
 
   def wu_weather_multi(m, xml)
-    stations = xml.scan(/<td>\s*<a href="\/(?:global\/stations|US\/(\w\w))\/(.*?)\.html">(.*?)<\/a>\s*:\s*(.*?)<\/td>/m)
+    # debug xml
+    stations = xml.scan(/<td>\s*(?:<a href="([^?"]+\?feature=[^"]+)"\s*[^>]*><img [^>]+><\/a>\s*)?<a href="\/(?:global\/stations|US\/(\w\w))\/([^"]*?)\.html">(.*?)<\/a>\s*:\s*(.*?)<\/td>/m)
+    # debug stations
     m.reply "multiple stations available, use 'weather station <code>' or 'weather <city, state>' as appropriate, for one of the following (current temp shown):"
     stations.map! { |ar|
-      if ar.first # US state
-        "%s, %s (%s): %s" % [ar[1], ar[0], ar[2], wu_clean(ar[3])]
+      warning = ar[0]
+      loc = ar[2]
+      state = ar[1]
+      par = ar[3]
+      w = ar[4]
+      if state # US station
+        (warning ? "*" : "") + ("%s, %s (%s): %s" % [loc, state, par, wu_clean(w)])
       else # non-US station
-        "station %s (%s): %s" % [ar[1], ar[2], wu_clean(ar[3])]
+        (warning ? "*" : "") + ("station %s (%s): %s" % [loc, par, wu_clean(w)])
       end
     }
     m.reply stations.join("; ")