1 #Tube Status Enquiry plugin for rbot
2 #Plugin by Colm Linehan
4 class TubePlugin < Plugin
6 def help(plugin, topic="")
7 "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"
12 tube_page = @bot.httputil.get('http://www.tfl.gov.uk/tfl/livetravelnews/realtime/tube/default.html')
14 m.reply "Cannot contact Tube Service Status page"
18 tube_page.each_line {|l|
22 if (l =~ /^<p>\s*(.*)<\/p>/i)
23 m.reply $1.split(/<[^>]+>| /i).join(" ")
25 elsif l =~ /ul|h3|"message"/
28 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."
32 next_line = true if (l =~ /li class="#{line}"/i)
34 m.reply "No Problems on the #{line} line."
37 def check_stations(m, params)
38 tube_page = @bot.httputil.get('http://www.tfl.gov.uk/tfl/service_rt_tube.shtml')
40 m.reply "Cannot contact Tube Service Status page"
43 stations_array = Array.new
44 tube_page.each_line {|l|
45 if (l =~ /<tr valign=top> <td valign="middle" class="Station"><b>(.*)<\/b><\/td><\/tr>\s*/i)
46 stations_array.push $1
49 if stations_array.empty?
50 m.reply "There are no station-specific announcements"
53 m.reply stations_array.join(", ")
58 plugin = TubePlugin.new
59 # plugin.map 'tube stations', :action => 'check_stations'
60 plugin.map 'tube :line'