From: Giuseppe Bilotta Date: Wed, 11 May 2011 16:18:04 +0000 (+0200) Subject: weather: URI-encode station X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=7d2f6b2aa00632f55df231c72cec7661af8845f1;hp=3e96282cc12d4aacfce314a954ca602f0d89b92a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git weather: URI-encode station The NWS code assumed that the station could be used as-is in the URL, which is actually true for the station codes accepted by NWS, but incorrect in general. People with NWS as the default weather service would get strange errors about bad URIs if trying something like "weather birmingham, uk". Solve by URI-encoding the station name: even if the resulting URL will still give a 404, at least it doesn't give out odd errors. --- diff --git a/data/rbot/plugins/weather.rb b/data/rbot/plugins/weather.rb index 0d3abee2..cda68e10 100644 --- a/data/rbot/plugins/weather.rb +++ b/data/rbot/plugins/weather.rb @@ -17,7 +17,7 @@ require 'rexml/document' class CurrentConditions def initialize(station) @station = station - @url = "http://www.nws.noaa.gov/data/current_obs/#{@station.upcase}.xml" + @url = "http://www.nws.noaa.gov/data/current_obs/#{URI.encode @station.upcase}.xml" @etag = String.new @mtime = Time.mktime(0) @current_conditions = String.new