From 29ea55aa6316067939e7e2871107d51179d92755 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 26 Jan 2011 13:11:26 +0100 Subject: [PATCH] weather: use bot standard html cleanup functions Get rid of wu_clean and replace it with ircify_html or riphtml depending on context. --- data/rbot/plugins/weather.rb | 34 +++++++++++----------------------- 1 file 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!(/]*?>/,'') - txt.gsub!(//,'') - txt - end - def wu_weather_multi(m, xml) # debug xml stations = xml.scan(/\s*(?:]*>]+><\/a>\s*)?(.*?)<\/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(/\s*\s*(.*?)\s*<\/td>\s*\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(/\s*\s*(.*?)\s*<\/td>\s*\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 -- 2.32.0.93.g670b81a890