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"
16 tube_page = @bot.httputil.get_cached(URI.parse("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml"), 1, 1)
17 rescue URI::InvalidURIError, URI::BadURIError => e
18 m.reply "Cannot contact Tube Service Status page"
22 m.reply "Cannot contact Tube Service Status page"
26 tube_page.each_line {|l|
30 if (l =~ /^<tr valign=top> <td>\s*(.*)<\/td><\/tr>/i)
31 m.reply $1.split(/<[^>]+>| /i).join(" ")
34 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."
38 next_line = true if (l =~ /class="#{line}"/i)
40 m.reply "No Problems on the #{line} line."
43 def check_stations(m, params)
45 tube_page = @bot.httputil.get_cached(URI.parse("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml"))
46 rescue URI::InvalidURIError, URI::BadURIError => e
47 m.reply "Cannot contact Tube Service Status page"
51 m.reply "Cannot contact Tube Service Status page"
54 stations_array = Array.new
55 tube_page.each_line {|l|
56 if (l =~ /<tr valign=top> <td valign="middle" class="Station"><b>(.*)<\/b><\/td><\/tr>\s*/i)
57 stations_array.push $1
60 if stations_array.empty?
61 m.reply "There are no station-specific announcements"
64 m.reply stations_array.join(", ")
69 plugin = TubePlugin.new
70 plugin.map 'tube stations', :action => 'check_stations'
71 plugin.map 'tube :line'