Sha256: 7cab1a07afbd2f3247fb9f0329537ed6872fb9ffea5bf1c82a7e6719395d1430

Contents?: true

Size: 982 Bytes

Versions: 6

Compression:

Stored size: 982 Bytes

Contents

#
# Loading XML Data
# by Daniel Shiffman.  
#
# This example demonstrates how to use loadXML
# to retrieve data from an XML document via a URL
#

attr_reader :zip, :weather, :temperature

def setup
  size(600, 360)
  @zip = 10003
  font = create_font('Times Roman', 28)
  # font = create_font('Merriweather-Light.ttf', 28)
  text_font(font)

  # The URL for the XML document
  url = "http://xml.weather.yahoo.com/forecastrss?p=#{zip}"
  
  # Load the XML document
  xml = loadXML(url)

  # Grab the element we want
  forecast = xml.get_child('channel').get_child('item').get_child('yweather:forecast')
  
  # Get the attributes we want
  @temperature = forecast.get_int('high')
  @weather = forecast.get_string('text')
end

def draw
  background(255)
  fill(0)
  # Display all the stuff we want to display
  text("Zip code: #{zip}", width*0.15, height*0.33)
  text("Today's high: #{temperature}", width*0.15, height*0.5)
  text("Forecast: #{weather}", width*0.15, height*0.66)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/processing_app/topics/advanced_data/yahoo_weather.rb
ruby-processing-2.6.2 samples/processing_app/topics/advanced_data/yahoo_weather.rb
ruby-processing-2.6.1 samples/processing_app/topics/advanced_data/yahoo_weather.rb
ruby-processing-2.6.0 samples/processing_app/topics/advanced_data/yahoo_weather.rb
ruby-processing-2.5.1 samples/processing_app/topics/advanced_data/yahoo_weather.rb
ruby-processing-2.5.0 samples/processing_app/topics/advanced_data/yahoo_weather.rb