Last active
August 29, 2015 14:03
-
-
Save venj/7060ebefb3679967a3b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Will download to Files in current directory. | |
# To download: | |
# ruby down.rb | |
require "open-uri" | |
require "fileutils" | |
include FileUtils | |
USER = "data_public" | |
PWD = "GDdci" | |
BASE_URL = "http://data.cgiar-csi.org/srtm/tiles/ASCII/" | |
print "Parsing directory..." | |
lines = open(BASE_URL, :http_basic_authentication => [USER, PWD]).readlines | |
puts "done." | |
puts | |
regex = />([^<>]+?\.zip)</ | |
target = "Files" | |
mkdir target unless File.exists? target | |
lines.each do |l| | |
matches = regex.match(l) | |
next if matches.nil? | |
cd target do | |
file = matches[1] | |
print "Downloading #{file}..." | |
open(file, "wb") { |f| f.write open(BASE_URL + regex.match(l)[1], :http_basic_authentication => [USER, PWD]).read } | |
puts "done." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment