diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2011-01-26 13:11:26 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2011-01-26 13:37:39 +0100 |
commit | 29ea55aa6316067939e7e2871107d51179d92755 (patch) | |
tree | 76a8fafc3ac861efedecf927729bdc2b7cd3e3bb /data/rbot/plugins/weather.rb | |
parent | a6e1d47056be249989cbe40233422d4644d88739 (diff) |
weather: use bot standard html cleanup functions
Get rid of wu_clean and replace it with ircify_html or riphtml depending
on context.
Diffstat (limited to 'data/rbot/plugins/weather.rb')
-rw-r--r-- | data/rbot/plugins/weather.rb | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/data/rbot/plugins/weather.rb b/data/rbot/plugins/weather.rb index afcf394c..b3f9a68b 100644 --- a/data/rbot/plugins/weather.rb +++ b/data/rbot/plugins/weather.rb @@ -223,18 +223,6 @@ class WeatherPlugin < Plugin end end - def wu_clean(stuff) - txt = stuff - txt.gsub!(/[\n\s]+/,' ') - txt.gsub!(/ /, ' ') - txt.gsub!(/°/, ' ') # degree sign - txt.gsub!(/<\/?b>/,'') - txt.gsub!(/<\/?span[^<>]*?>/,'') - txt.gsub!(/<img\s*[^<>]*?>/,'') - txt.gsub!(/<br\s?\/?>/,'') - txt - end - def wu_weather_multi(m, xml) # 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) @@ -247,9 +235,9 @@ class WeatherPlugin < Plugin par = ar[3] w = ar[4] if state # US station - (warning ? "*" : "") + ("%s, %s (%s): %s" % [loc, state, par, wu_clean(w)]) + (warning ? "*" : "") + ("%s, %s (%s): %s" % [loc, state, par, w.ircify_html]) else # non-US station - (warning ? "*" : "") + ("station %s (%s): %s" % [loc, par, wu_clean(w)]) + (warning ? "*" : "") + ("station %s (%s): %s" % [loc, par, w.ircify_html]) end } m.reply stations.join("; ") @@ -289,17 +277,17 @@ class WeatherPlugin < Plugin end def wu_weather_filter(stuff) - txt = wu_clean(stuff) - result = Array.new - if txt.match(/<\/a>\s*Updated:\s*(.*?)\s*Observed at\s*(.*?)\s*<\/td>/) - result << ("Weather info for %s (updated on %s)" % [$2, $1]) + if stuff.match(/<\/a>\s*Updated:\s*(.*?)\s*Observed at\s*(.*?)\s*<\/td>/) + result << ("Weather info for %s (updated on %s)" % [$2.ircify_html, $1.ircify_html]) end - txt.scan(/<tr>\s*<td>\s*(.*?)\s*<\/td>\s*<td>\s*(.*?)\s*<\/td>\s*<\/tr>/) { |k, v| - next if v.empty? - next if ["-", "- approx.", "N/A", "N/A approx."].include?(v) - next if k == "Raw METAR" - result << ("%s: %s" % [k, v]) + stuff.scan(/<tr>\s*<td>\s*(.*?)\s*<\/td>\s*<td>\s*(.*?)\s*<\/td>\s*<\/tr>/m) { |k, v| + kk = k.riphtml + vv = v.riphtml + next if vv.empty? + next if ["-", "- approx.", "N/A", "N/A approx."].include?(vv) + next if kk == "Raw METAR" + result << ("%s: %s" % [kk, vv]) } return result.join('; ') end |