From: Tom Gilbert Date: Thu, 21 Jul 2005 11:02:04 +0000 (+0000) Subject: rework the tube plugin's html parser a bit, to enable it to work properly X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=e3c4d9ad30b8548c09dd7d26abdfeef223c23f40;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git rework the tube plugin's html parser a bit, to enable it to work properly with tricky station names, such as hammersmity & city. --- diff --git a/rbot/plugins/tube.rb b/rbot/plugins/tube.rb index 98b90c6c..77ca5227 100644 --- a/rbot/plugins/tube.rb +++ b/rbot/plugins/tube.rb @@ -29,26 +29,27 @@ class TubePlugin < Plugin m.reply "Cannot contact Tube Service Status page" return end + next_line = false tube_page.each_line {|l| - if (l =~ /class="#{line}"/i) - tube_page.each_line { |l2| - if (l2 =~ /^ \s*(.*#{line}.*)<\/td><\/tr>/i) - problem_message = Array.new - problem_message = $1.split(/<[^>]+>| /i) - m.reply problem_message.join(" ") - return - end - } + next if l == "\r\n" + next if l == "\n" + if (next_line) + if (l =~ /^ \s*(.*)<\/td><\/tr>/i) + m.reply $1.split(/<[^>]+>| /i).join(" ") + return + else m.reply "There are problems on the #{line} line, but I didn't understand the page format. You should check out http://www.tfl.gov.uk/tfl/service_rt_tube.shtml for more details." return end - } + end + next_line = true if (l =~ /class="#{line}"/i) + } m.reply "No Problems on the #{line} line." end def check_stations(m) begin - tube_page = Utils.http_get("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml") + tube_page = @bot.httputil.get(URI.parse("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml")) rescue URI::InvalidURIError, URI::BadURIError => e m.reply "Cannot contact Tube Service Status page" return