Nov 15 2006
Fichier weather.rb
require 'uri'
require 'net/http'
require 'rexml/document'
city=URI.escape(ARGV[0])
url="http://xoap.weather.com/search/search?where="+city
puts "search..."+url
r=Net::HTTP.get_response URI.parse(url)
if not r:
puts "no city"
exit
end
doc=REXML::Document.new r.body
codedcity=""
doc.elements.each("/search/loc") {|element|
codedcity=element.attributes["id"].to_s
puts "\ncode for "+city+" = "+codedcity
url2="http://xoap.weather.com/weather/local/"+codedcity+ Fichier [weather.rb](ftp://feelfree.homelinux.com/pub/ruby/weather.rb)
require 'uri'
require 'net/http'
require 'rexml/document'
city=URI.escape(ARGV[0])
url="http://xoap.weather.com/search/search?where="+city
puts "search..."+url
r=Net::HTTP.get_response URI.parse(url)
if not r:
puts "no city"
exit
end
doc=REXML::Document.new r.body
codedcity=""
doc.elements.each("/search/loc") {|element|
codedcity=element.attributes["id"].to_s
puts "\ncode for "+city+" = "+codedcity
url2="http://xoap.weather.com/weather/local/"+codedcity+
require 'uri'
require 'net/http'
require 'rexml/document'
city=URI.escape(ARGV[0])
url="http://xoap.weather.com/search/search?where="+city
puts "search..."+url
r=Net::HTTP.get_response URI.parse(url)
if not r:
puts "no city"
exit
end
doc=REXML::Document.new r.body
codedcity=""
doc.elements.each("/search/loc") {|element|
codedcity=element.attributes["id"].to_s
puts "\ncode for "+city+" = "+codedcity
url2="http://xoap.weather.com/weather/local/"+codedcity+ Fichier [weather.rb](ftp://feelfree.homelinux.com/pub/ruby/weather.rb)
require 'uri'
require 'net/http'
require 'rexml/document'
city=URI.escape(ARGV[0])
url="http://xoap.weather.com/search/search?where="+city
puts "search..."+url
r=Net::HTTP.get_response URI.parse(url)
if not r:
puts "no city"
exit
end
doc=REXML::Document.new r.body
codedcity=""
doc.elements.each("/search/loc") {|element|
codedcity=element.attributes["id"].to_s
puts "\ncode for "+city+" = "+codedcity
url2="http://xoap.weather.com/weather/local/"+codedcity+ \
"?cc=*%E2%88%8F=xoap&par=xxx&key=xxx&unit=m"
r2=Net::HTTP.get_response URI.parse(url2)
if not r2:
puts "no data for "+codedcity
exit
end
weather=REXML::Document.new r2.body
dnam=weather.elements.to_a("//dnam")
puts dnam[0].text
temperature=weather.elements.to_a("//tmp")
puts temperature[0].text
wtype=weather.elements.to_a("//cc/t")
puts wtype[0].text
puts "-"*30
}
usage:
ruby weather.rb washington
#x000A; "?cc=*%E2%88%8F=xoap&par=xxx&key=xxx&unit=m"
r2=Net::HTTP.get_response URI.parse(url2)
if not r2:
puts "no data for "+codedcity
exit
end
weather=REXML::Document.new r2.body
dnam=weather.elements.to_a("//dnam")
puts dnam[0].text
temperature=weather.elements.to_a("//tmp")
puts temperature[0].text
wtype=weather.elements.to_a("//cc/t")
puts wtype[0].text
puts "-"*30
}
#x000A; "?cc=*%E2%88%8F=xoap&par=xxx&key=xxx&unit=m"
r2=Net::HTTP.get_response URI.parse(url2)
if not r2:
puts "no data for "+codedcity
exit
end
weather=REXML::Document.new r2.body
dnam=weather.elements.to_a("//dnam")
puts dnam[0].text
temperature=weather.elements.to_a("//tmp")
puts temperature[0].text
wtype=weather.elements.to_a("//cc/t")
puts wtype[0].text
puts "-"*30
}
usage:
ruby weather.rb washington
#x000A; "?cc=*%E2%88%8F=xoap&par=xxx&key=xxx&unit=m"
r2=Net::HTTP.get_response URI.parse(url2)
if not r2:
puts "no data for "+codedcity
exit
end
weather=REXML::Document.new r2.body
dnam=weather.elements.to_a("//dnam")
puts dnam[0].text
temperature=weather.elements.to_a("//tmp")
puts temperature[0].text
wtype=weather.elements.to_a("//cc/t")
puts wtype[0].text
puts "-"*30
}
usage:
ruby weather.rb washington
comments : 0 Add comment
