Hello all. I have my code able to successfully print out a weather report using Nokogiri from the Aviationweather.gov website.
The code prompts the user to input a weather station name, for example: KORD =>(This is the code for Chicago Airport) It puts this variable to upcase method then inserts it into a Nokogiri Open url
This gathers all the information at the XML location and puts it into
docOnce there. I am having trouble using and filtering the data with gsub. I want to get all the data between "<raw_data> and </raw_data> only and exclude the rest in output. How can this be done? Any help would be appreciated! Thanks so much
print "Metar Station Name: "
metar = gets.chomp
metar.upcase!
if metar.length == 3 || metar.length == 4
puts "Searching..."
require "rubygems"
require "nokogiri"
require 'open-uri'
doc = Nokogiri::XML(open("
http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString=#{metar}"))
output = @doc[/#{metar}(.*?)<\/raw_text>/, 1]
while output.include? "</raw_text>"
output.gsub!(/<\/raw_text>/, "")
end
puts output
else
print "\"#{metar}\" is not a valid airport identifier. Please use a 3 or 4 letter valid airport code. For example: KATL for Atlanta Georgia.\n"
end