Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [SOLUTION] Current Temperature (#68)

Reply
Thread Tools

[SOLUTION] Current Temperature (#68)

 
 
semmons99@gmail.com
Guest
Posts: n/a
 
      02-26-2006
# Author: Shane Emmons
#
# Allows retrieval of current temperature information. Pretty simple
# and straight forward. Uses match to extract data from the xml
document
# that is returned. Sorry about the long lines, but I like putting as
# much code in one line as possible.
#
# usage: ruby current_temp.rb [zipcode|other]
#
# zipcode: US zipcode
# other: country code information. example: SPXX0050 for Madrid,
Spain

require 'net/http'

begin
weather_info = Net::HTTP.get( "xml.weather.yahoo.com",
"/forecastrss?p=".concat( ARGV[ 0 ] ) )
print "The temperature in ", weather_info.match( /Yahoo! Weather
for (.*)</ )[ 1 ], " is ", weather_info.match(
/<yweather:condition.*temp="(\d+)"/ )[ 1 ], " degrees ",
weather_info.match( /<yweather:units temperature="(.)"/ )[ 1 ], ".\n"
rescue
print "Information for ", ARGV[ 0 ], " was not found or
unavailable."
end

 
Reply With Quote
 
 
 
 
James Edward Gray II
Guest
Posts: n/a
 
      02-26-2006
On Feb 26, 2006, at 7:53 AM, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Sorry about the long lines, but I like putting as much code in one
> line as possible.


Repeat after me:

"Horizontal scrolling is bad... Horizontal scrolling is bad...
Horizontal scrolling is bad..."



Seriously, thanks you for the submission.

James Edward Gray II



 
Reply With Quote
 
 
 
 
semmons99@gmail.com
Guest
Posts: n/a
 
      02-27-2006
# Author: Shane Emmons
#
# Allows retrieval of current temperature information. Pretty simple
# and straight forward. Uses match to extract data from the xml
# document that is returned. Adjusted for easier horizontal reading.

#
# usage: ruby current_temp.rb [zipcode|other]
#
# zipcode: US zipcode
# other: country code information.
# example: SPXX0050 for Madrid, Spain

require 'net/http'

ARGV[ 0 ] = '48601'

begin
info = Net::HTTP.get(
"xml.weather.yahoo.com", "/forecastrss?p=".concat( ARGV[ 0 ] )
)

location = info.match( /Yahoo! Weather for (.*)</ )[ 1 ]
temperature = info.match( /<yweather:condition.*temp="(\d+)"/ )[ 1
]
measured_in = info.match( /<yweather:units temperature="(.)"/ )[ 1
]

print "The temperature in ",
location, " is ", temperature, " degrees ", measured_in, ".\n"
rescue
print "Information for #{ ARGV[ 0 ] } was not found or
unavailable.\n"
end

 
Reply With Quote
 
semmons99@gmail.com
Guest
Posts: n/a
 
      02-27-2006
** Sorry had my test code still in there for my location

# Author: Shane Emmons
#
# Allows retrieval of current temperature information. Pretty simple
# and straight forward. Uses match to extract data from the xml
# document that is returned. Adjusted for easier horizontal reading.

#
# usage: ruby current_temp.rb [zipcode|other]
#
# zipcode: US zipcode
# other: country code information.
# example: SPXX0050 for Madrid, Spain

require 'net/http'

begin
info = Net::HTTP.get(
"xml.weather.yahoo.com", "/forecastrss?p=".concat( ARGV[ 0 ] )
)

location = info.match( /Yahoo! Weather for (.*)</ )[ 1 ]
temperature = info.match( /<yweather:condition.*temp="(\d+)"/ )[ 1
]
measured_in = info.match( /<yweather:units temperature="(.)"/ )[ 1
]

print "The temperature in ",
location, " is ", temperature, " degrees ", measured_in, ".\n"
rescue
print "Information for #{ ARGV[ 0 ] } was not found or
unavailable.\n"
end

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SUMMARY] Current Temperature (#68) Ruby Quiz Ruby 1 03-02-2006 02:14 PM
[SOLUTION] Current Temperature (#68) David Tran Ruby 2 03-02-2006 08:21 AM
[QUIZ] Current Temperature (#68) Ruby Quiz Ruby 19 03-01-2006 01:59 AM
[SOLUTION] Current Temperature (#68) David Tran Ruby 0 02-27-2006 09:23 PM
[SOLUTION] Current Temperature (#68) Rudolfs Osins Ruby 1 02-26-2006 05:57 PM



Advertisments