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.
66e5b65d1fe0183ca04053fda407a185?d=identicon&s=25 Rudolfs Osins (Guest)
on 2006-02-26 18:19
(Received via mailing list)
Hello everyone !

Here is my solution, actually it's my first ruby program, I just
started learning... Suggestions on how to improve my code are
welcome :)

This is how it looks when executed, I couldn't find where to turn
these warnings off :/

------------------------------------------------------------------

root@black /# ./weather.rb madrid
ignored element: {http://schemas.xmlsoap.org/wsdl/http/}binding
ignored element: {http://schemas.xmlsoap.org/wsdl/http/}operation
ignored element: {http://schemas.xmlsoap.org/wsdl/http/}urlEncoded
ignored element: {http://schemas.xmlsoap.org/wsdl/mime/}mimeXml
ignored element: {http://schemas.xmlsoap.org/wsdl/mime/}content
ignored element: {http://schemas.xmlsoap.org/wsdl/http/}address
The temperature in Madrid / Cuatro Vientos is 3 C

------------------------------------------------------------------

#!/usr/local/bin/ruby
require 'soap/wsdlDriver'
require 'rexml/document'

URL = 'http://www.webservicex.net/globalweather.asmx?WSDL'

# process the comandline arguments
if ARGV[0] == nil
  abort("Usage: weather.rb city")
else
  city = ARGV.join(' ')
end

soap = SOAP::WSDLDriverFactory.new(URL).create_rpc_driver
begin
  weather = soap.GetWeather(:CityName => city, :CountryName => "")

  # strip the first line with <? ?> stuff, else REXML wont parse
  xml = weather.getWeatherResult.gsub(/(<\?.*?>\n)/, '')
  data = REXML::Document.new(xml)

  # celsius degrees are in parentheses
  data.elements["//Temperature"].text[/\((.*)\)/]; temp = $1
  data.elements["//Location"].text[/^(.*),/]; loc = $1

  # show the gathered data
  puts "The temperature in " + loc + " is " + temp
rescue
  puts "Could not find data for your supplied city: " + city
end

------------------------------------------------------------------

Best regards,
Rudolfs
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 Christian Neukirchen (Guest)
on 2006-02-26 18:39
(Received via mailing list)
Rudolfs Osins <dev.random@gmail.com> writes:

> Here is my solution, actually it's my first ruby program, I just
> started learning... Suggestions on how to improve my code are
> welcome :)
>
> This is how it looks when executed, I couldn't find where to turn
> these warnings off :/

$-w = nil  should work.

Actually, I tried to use this webservice too, but I got so mad at it
and it's freaking dumb semantics that I dropped that for health
reasons.  Looks like you did it, though. ;-)
66e5b65d1fe0183ca04053fda407a185?d=identicon&s=25 Rudolfs Osins (Guest)
on 2006-02-26 19:00
(Received via mailing list)
> $-w = nil  should work.
>
> Actually, I tried to use this webservice too, but I got so mad at it
> and it's freaking dumb semantics that I dropped that for health
> reasons.  Looks like you did it, though. ;-)
>
> --
> Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org
>

Yay, that works, no warnings anymore :) Where can I read more about this
magic
$-w variable ?

Regards,
Rudolfs
This topic is locked and can not be replied to.