-
-
Save ichoake/5719c85574cb240122c609f038000f93 to your computer and use it in GitHub Desktop.
download all the listing images from a given etsy shop
This file contains hidden or 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
| require 'etsy' | |
| Etsy.api_key = '<api-key>' | |
| shop = Etsy::Shop.find '<shop-name>' | |
| out_dir = '<output-directory>' | |
| Etsy.environment = :production | |
| Dir.mkdir out_dir unless File.exists? out_dir | |
| listings = [] | |
| offset = 0 | |
| begin | |
| nListings = listings.length | |
| listings.concat Etsy::Listing.find_all_by_shop_id(shop.id, :limit => 100, :offset => offset) | |
| offset += 100 | |
| end while listings.length > nListings | |
| images = listings.map {|l| l.images.map {|i| i.full } } | |
| images.flatten! | |
| images.map do |image_url| | |
| uri = URI.parse image_url | |
| out_file = File.join out_dir, File.basename(uri.path) | |
| unless File.exists? out_file | |
| response = Net::HTTP.get_response uri | |
| File.open(out_file, "w"){|f| f.write response.body } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment