summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/tube.rb
diff options
context:
space:
mode:
authorDmitry Kim <dmitry point kim at gmail point com>2007-03-30 23:44:02 +0000
committerDmitry Kim <dmitry point kim at gmail point com>2007-03-30 23:44:02 +0000
commitb11c3c4042b03e36639370002ecf86c44f7ddde4 (patch)
tree05a35024a2d56c7e3d313317376a17cb7c41a99f /data/rbot/plugins/tube.rb
parentb73d6c7dc6554e1c6eb6abce68350ed2c13191b8 (diff)
*** (httputil) major rework, new caching implementation, unified request
processing + (httputil) post support, partial request support, other features - (httputil) removed partial_body() and get_cached() [merged into get()] * (plugins/, utils) minimal changes to accomodate for the new http_utils * (utils, ircbot) moved utils initialization into utils.rb * (tube.rb) (partially) accomodate for upstream site layout changes
Diffstat (limited to 'data/rbot/plugins/tube.rb')
-rw-r--r--data/rbot/plugins/tube.rb64
1 files changed, 28 insertions, 36 deletions
diff --git a/data/rbot/plugins/tube.rb b/data/rbot/plugins/tube.rb
index 0a9feb2f..16562274 100644
--- a/data/rbot/plugins/tube.rb
+++ b/data/rbot/plugins/tube.rb
@@ -7,56 +7,48 @@ require 'uri/common'
class TubePlugin < Plugin
include REXML
def help(plugin, topic="")
- "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"
+ "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"
end
def tube(m, params)
line = params[:line]
- begin
- tube_page = @bot.httputil.get_cached(URI.parse("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml"), 1, 1)
- rescue URI::InvalidURIError, URI::BadURIError => e
- m.reply "Cannot contact Tube Service Status page"
- return
- end
- unless tube_page
- m.reply "Cannot contact Tube Service Status page"
- return
- end
- next_line = false
- tube_page.each_line {|l|
- next if l == "\r\n"
- next if l == "\n"
- if (next_line)
- if (l =~ /^<tr valign=top> <td>\s*(.*)<\/td><\/tr>/i)
- m.reply $1.split(/<[^>]+>|&nbsp;/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
+ tube_page = @bot.httputil.get('http://www.tfl.gov.uk/tfl/livetravelnews/realtime/tube/default.html')
+ unless tube_page
+ m.reply "Cannot contact Tube Service Status page"
+ return
end
- next_line = true if (l =~ /class="#{line}"/i)
+ next_line = false
+ tube_page.each_line {|l|
+ next if l == "\r\n"
+ next if l == "\n"
+ if (next_line)
+ if (l =~ /^<p>\s*(.*)<\/p>/i)
+ m.reply $1.split(/<[^>]+>|&nbsp;/i).join(" ")
+ return
+ elsif l =~ /ul|h3|"message"/
+ next
+ 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/livetravelnews/realtime/tube/default.html for more details."
+ return
+ end
+ end
+ next_line = true if (l =~ /li class="#{line}"/i)
}
- m.reply "No Problems on the #{line} line."
+ m.reply "No Problems on the #{line} line."
end
def check_stations(m, params)
- begin
- tube_page = @bot.httputil.get_cached(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
- end
+ tube_page = @bot.httputil.get('http://www.tfl.gov.uk/tfl/service_rt_tube.shtml')
unless tube_page
m.reply "Cannot contact Tube Service Status page"
return
end
stations_array = Array.new
tube_page.each_line {|l|
- if (l =~ /<tr valign=top> <td valign="middle" class="Station"><b>(.*)<\/b><\/td><\/tr>\s*/i)
- stations_array.push $1
- end
- }
+ if (l =~ /<tr valign=top> <td valign="middle" class="Station"><b>(.*)<\/b><\/td><\/tr>\s*/i)
+ stations_array.push $1
+ end
+ }
if stations_array.empty?
m.reply "There are no station-specific announcements"
return
@@ -67,5 +59,5 @@ class TubePlugin < Plugin
end
end
plugin = TubePlugin.new
-plugin.map 'tube stations', :action => 'check_stations'
+# plugin.map 'tube stations', :action => 'check_stations'
plugin.map 'tube :line'