RealCasually
RealCasually

Reputation: 3613

Get list of files from Apache index page using Ruby/Rails

I am attempting to create a radar animation using data from the National Weather Service. For static images they make it easy by always having the same filename. However, for the historical images, they are timestamped, and always change. Thus, to get the previous N images, you would have to know the filenames beforehand. They do, however, provide a directory which provides a listing for each site. See the example here: http://radar.weather.gov/ridge/RadarImg/N0R/FWS/

What I need is from my Rails app to extract the last N images from that directory. Is that possible? I could imagine one option would be to download and then scrape that page, but I am assuming there is a better way?

Thanks!

Upvotes: 0

Views: 290

Answers (2)

stew
stew

Reputation: 275

Following on from the above you could try something like I just tried in the console..

require 'open-uri'
require 'nokogiri'    
doc = Nokogiri::HTML(open('http://radar.weather.gov/ridge/RadarImg/N0R/FWS/'))
doc.xpath('//table/tr/td').each do |tabrow|
  puts tabrow.content
end

That's a pretty basic stab in the dark but should give you food for thought to get you on the way

Upvotes: 2

tadman
tadman

Reputation: 211670

You'll have to download them using a library like curb, parse the page with something like Nokogiri and then combine the images using whatever tool works best for you.

Rails is designed to handle web requests, not run as a background job, but there are tools that can facilitate this for you or you can always make scripts for rails runner to execute in the Rails environment.

Upvotes: 1

Related Questions