#!/usr/bin/ruby require 'net/http' require 'xmlsimple' RSS_FEED_URL_LONDON = 'http://xml.weather.yahoo.com/forecastrss?p=CAXX0114&u=c' RSS_FEED_URL_COLLINGWOOD = 'http://xml.weather.yahoo.com/forecastrss?p=CAXX0090&u=c' begin text_london = Net::HTTP.get(URI.parse(RSS_FEED_URL_LONDON)) text_collingwood = Net::HTTP.get(URI.parse(RSS_FEED_URL_COLLINGWOOD)) rescue puts "ERROR: Failed fetching RSS feed!" exit end begin xml_london = XmlSimple.xml_in(text_london) channel_london = xml_london['channel'][0] xml_collingwood = XmlSimple.xml_in(text_collingwood) channel_collingwood = xml_collingwood['channel'][0] rescue puts "Error: Could not parse the XML!" exit end temp_units = channel_london['units'][0]['temperature'] puts "weather" puts " location london @ " + channel_london['lastBuildDate'][0].sub(/..., \d\d ... \d\d\d\d /,'').downcase puts " temp " + channel_london['item'][0]['condition'][0]['temp'] + temp_units.downcase puts " cond " + channel_london['item'][0]['condition'][0]['text'].downcase puts " location collingwood @ " + channel_collingwood['lastBuildDate'][0].sub(/..., \d\d ... \d\d\d\d /,'').downcase puts " temp " + channel_collingwood['item'][0]['condition'][0]['temp'] + temp_units.downcase puts " cond " + channel_collingwood['item'][0]['condition'][0]['text'].downcase