# Current Temperature (#68)

**URL:** <https://www.ruby-forum.com/t/current-temperature-68/73433>\
**Category:** Ruby\
**Created:** [February 26, 2006, 2:54pm UTC](https://www.ruby-forum.com/t/current-temperature-68/73433 "2006-02-26T14:54:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 26, 2006, 2:54pm UTC](https://www.ruby-forum.com/t/current-temperature-68/73433/1 "2006-02-26T14:54:28Z")

</div>

# 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](http://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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 26, 2006, 5:39pm UTC](https://www.ruby-forum.com/t/current-temperature-68/73433/2 "2006-02-26T17:39:16Z")

</div>

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…”

😃

Seriously, thanks you for the submission.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/current-temperature-68/73433/3 "2006-02-27T17:42:23Z")

</div>

# 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](http://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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 3, 2006, 1:45pm UTC](https://www.ruby-forum.com/t/current-temperature-68/73433/4 "2006-08-03T13:45:40Z")

</div>

\*\* 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](http://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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 3, 2006, 2:22pm UTC](https://www.ruby-forum.com/t/current-temperature-68/73433/5 "2006-08-03T14:22:18Z")

</div>

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
