1 #Tube Status Enquiry plugin for rbot
2 #Plugin by Colm Linehan
4 require 'rexml/document'
7 class TubePlugin < Plugin
9 def help(plugin, topic="")
10 "tube [district|circle|metropolitan|central|jubilee|bakerloo|waterloo_city|hammersmith_city|victoria|eastlondon|northern|piccadilly] => display tube service status for the specified line(Docklands Light Railway is not currently supported), tube stations => list tube stations (not lines) with problems"
13 if m.params && m.params =~ /^stations$/
15 elsif m.params && m.params =~ /^(.*)$/
16 line = $1.downcase.capitalize
21 def check_tube(m, line)
23 tube_page = Utils.http_get("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml")
24 rescue URI::InvalidURIError, URI::BadURIError => e
25 m.reply "Cannot contact Tube Service Status page"
29 m.reply "Cannot contact Tube Service Status page"
32 tube_page.each_line {|l|
33 if (l =~ /class="#{line}"/i)
34 tube_page.each_line { |l2|
35 if (l2 =~ /^<tr valign=top> <td>\s*(.*#{line}.*)<\/td><\/tr>/i)
36 problem_message = Array.new
37 problem_message = $1.split(/<[^>]+>| /i)
38 m.reply problem_message.join(" ")
42 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."
46 m.reply "No Problems on the #{line} line."
51 tube_page = Utils.http_get("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml")
52 rescue URI::InvalidURIError, URI::BadURIError => e
53 m.reply "Cannot contact Tube Service Status page"
57 m.reply "Cannot contact Tube Service Status page"
60 stations_array = Array.new
61 tube_page.each_line {|l|
62 if (l =~ /<tr valign=top> <td valign="middle" class="Station"><b>(.*)<\/b><\/td><\/tr>\s*/i)
63 stations_array.push $1
66 if stations_array.empty?
67 m.reply "There are no station-specific announcements"
70 m.reply stations_array.join(", ")
75 plugin = TubePlugin.new
76 plugin.register("tube")