1 #Tube Status Enquiry plugin for rbot
2 #Plugin by Colm Linehan
4 class TubePlugin < Plugin
5 def help(plugin, topic="")
6 "tube [district|circle|metropolitan|central|jubilee|bakerloo|waterlooandcity|hammersmithandcity|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"
11 tube_page = @bot.httputil.get('http://www.tfl.gov.uk/tfl/livetravelnews/realtime/tube/default.html')
13 m.reply "Cannot contact Tube Service Status page"
17 tube_page.each_line {|l|
21 if (l =~ /^<p>\s*(.*)<\/p>/i)
22 m.reply $1.split(/<[^>]+>| /i).join(" ")
24 elsif l =~ /ul|h3|"message"/
27 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/livetravelnews/realtime/tube/default.html for more details."
31 next_line = true if (l =~ /li class="#{line}"/i)
33 m.reply "No Problems on the #{line} line."
36 def check_stations(m, params)
37 tube_page = @bot.httputil.get('http://www.tfl.gov.uk/tfl/service_rt_tube.shtml')
39 m.reply "Cannot contact Tube Service Status page"
42 stations_array = Array.new
43 tube_page.each_line {|l|
44 if (l =~ /<tr valign=top> <td valign="middle" class="Station"><b>(.*)<\/b><\/td><\/tr>\s*/i)
45 stations_array.push $1
48 if stations_array.empty?
49 m.reply "There are no station-specific announcements"
52 m.reply stations_array.join(", ")
57 plugin = TubePlugin.new
58 # plugin.map 'tube stations', :action => 'check_stations'
59 plugin.map 'tube :line'