- def weather(m, params)
- if params[:where]
- @registry[m.sourcenick] = params[:where]
- describe(m,params[:where])
- else
- if @registry.has_key?(m.sourcenick)
- where = @registry[m.sourcenick]
- describe(m,where)
+ def wu_station(m, where, units)
+ begin
+ xml = @bot.httputil.get(@wu_station_url % [units, CGI.escape(where)])
+ case xml
+ when nil
+ m.reply "couldn't retrieve weather information, sorry"
+ return
+ when /Search not found:/
+ m.reply "no such station found (#{where})"
+ return
+ when /<table border.*?>(.*?)<\/table>/m
+ data = $1
+ m.reply wu_weather_filter(data)
+ else
+ debug xml
+ m.reply "something went wrong with the data for #{where}..."
+ end
+ rescue => e
+ m.reply "retrieving info about '#{where}' failed (#{e})"
+ end
+ end
+
+ def wu_weather(m, where, units)
+ begin
+ xml = @bot.httputil.get(@wu_url % [units, CGI.escape(where)])
+ case xml
+ when nil
+ m.reply "couldn't retrieve weather information, sorry"
+ when /City Not Found/
+ m.reply "no such location found (#{where})"
+ when /Current<\/a>/
+ data = ""
+ xml.scan(/<table border.*?>(.*?)<\/table>/m).each do |match|
+ data += wu_weather_filter(match.first)
+ end
+ if data.length > 0
+ m.reply data
+ else
+ m.reply "couldn't parse weather data from #{where}"
+ end
+ when /<a href="\/(?:global\/stations|US\/\w\w)\//
+ wu_weather_multi(m, xml)