]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
weather: URI-encode station
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 11 May 2011 16:18:04 +0000 (18:18 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 11 May 2011 16:18:04 +0000 (18:18 +0200)
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.

data/rbot/plugins/weather.rb

index 0d3abee27071cfc61de190ba0c47ef7dc7f92da2..cda68e102e5d0567299bd6a52724edc642967d0a 100644 (file)
@@ -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