Skip to content

Instantly share code, notes, and snippets.

@paractmol
Created October 16, 2016 03:23
Show Gist options
  • Save paractmol/7e9dcc03e40450cc9081129590610b92 to your computer and use it in GitHub Desktop.
Save paractmol/7e9dcc03e40450cc9081129590610b92 to your computer and use it in GitHub Desktop.
downloads_ny_photos_step_1
# First quick draft
require 'open-uri'
require 'uri'
class PhotoDownloader
RESOURCE = 'http://access.nypl.org/image.php/'
def initialize(id, dimension)
@id = id
@width, @height = dimension
end
def save
0.upto(@height-1) do |height|
0.upto(@width-1) do |width|
download(form_url(height, width), "#{@id}_#{height}_#{width}.png")
end
end
end
private
def download(uri, filepath)
File.write(filepath, uri.read, {mode: 'wb'})
end
def form_url(x,y)
URI.join(RESOURCE, "#{@id}/", fetch_tile(x,y))
end
def fetch_tile(x = 0, y = 0)
"tiles/0/11/#{x}_#{y}.png"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment