From: Robert Retzbach Date: 2006-02-28T03:18:10+09:00 Subject: Re: [QUIZ] Current Temperature (#68) Hello, I just want you to know my solution. Nothing special, but sharing is always good :) I'm looking forward at the summary. Bye. - require 'net/http' require 'uri' class Website def self.get(url) uri = URI.parse(url) begin res = Net::HTTP.start(uri.host, uri.port) do |http| http.get(uri.request_uri) end body = res.body rescue raise "Error: Failed to fetch page!" end return body end end if ARGV.first =~ /^[0-9]{5}$/ content = Website.get("http://www.weather.com/weather/local/#{ARGV.first}") name = content.scan(/
([^>]+) \(#{ARGV.first}\)/i).first.first else precontent = Website.get("http://www.weather.com/search/enhanced?what=WeatherLocalUndeclared&lswe=#{ARGV.join('+')}&lswa=WeatherLocalUndeclared&search=search&from=whatwhere&where=#{ARGV.join('+')}&whatprefs=&x=0&y=0") url, name = precontent.scan(%r#1. ([^<>]+)#i).first content = Website.get("http://www.weather.com/#{url}") end begin temp = content.scan(%r#([^<>]+)#i).first.first.sub(/°/, ' degrees ') rescue puts("Go and check your other geek devices!") end && puts("The temperatur in #{name} is #{temp}.")