Forum: Ruby Current Temperature (#68)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2006-02-26 15:54
(Received via mailing list)
# Author: Shane E.
#
# 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
James G. (Guest)
on 2006-02-26 18:39
(Received via mailing list)
On Feb 26, 2006, at 7:53 AM, removed_email_address@domain.invalid 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..."

:D

Seriously, thanks you for the submission.

James Edward G. II
(Guest)
on 2006-02-27 18:42
(Received via mailing list)
# Author: Shane E.
#
# 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
(Guest)
on 2006-08-03 15:45
(Received via mailing list)
** Sorry had my test code still in there for my location

# Author: Shane E.
#
# 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
James G. (Guest)
on 2006-08-03 16:22
(Received via mailing list)
On Feb 27, 2006, at 10:38 AM, removed_email_address@domain.invalid wrote:

> # ... Adjusted for easier horizontal reading. ;-)

I was just giving you a hard time, but that's so much for making the
change anyway.  This version is 1,000 times sexier, in my opinion.  ;)

James Edward G. II
This topic is locked and can not be replied to.