diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-03-26 22:17:18 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-03-26 22:17:18 +0100 |
commit | 03a565c6f6a11e950f66b7aa159de86c2119efee (patch) | |
tree | be225278b70f57ac59166ba3750d2852b535579f /data/rbot/plugins/weather.rb | |
parent | 6e62535cd38c5a1f00e76a6984df671d76e6c70a (diff) |
weather plugin: properly support and signal multiple weather stations when one has a special statement
Diffstat (limited to 'data/rbot/plugins/weather.rb')
-rw-r--r-- | data/rbot/plugins/weather.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/data/rbot/plugins/weather.rb b/data/rbot/plugins/weather.rb index b5835447..ff5f0537 100644 --- a/data/rbot/plugins/weather.rb +++ b/data/rbot/plugins/weather.rb @@ -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("; ") |