Created
January 27, 2012 06:47
-
-
Save kaixiang-li/1687514 to your computer and use it in GitHub Desktop.
查询天气脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
['rubygems','nokogiri','open-uri','yaml', 'iconv'].each {|lib| require lib} | |
location = ARGV.first or "wuhan" | |
google_url = "http://www.google.com/ig/api?weather=#{URI.encode(location)}" | |
weather = Nokogiri::XML(open(google_url),google_url,"ISO-8859-1") | |
w_info = weather.search('forecast_information').first | |
w_cond = weather.search('current_conditions').first | |
puts "Google: #{google_url}" | |
%w{condition temp_c humidity wind_condition}.each {|item| puts w_cond.search(item).first[:data]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment