Skip to content

Instantly share code, notes, and snippets.

@t2
Last active December 16, 2015 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t2/5490559 to your computer and use it in GitHub Desktop.
Save t2/5490559 to your computer and use it in GitHub Desktop.
Script to pull down images from a resource I found on Reddit
# You will need to install nokogiri and rubyzip gems
#
# gem install nokogiri
# gem install rubyzip
require 'nokogiri'
require 'open-uri'
require 'zip/zip'
IMAGES_URL = 'http://files.tinystudios.com/defaults/images/'
puts 'Building resources array...'
image_names = []
Nokogiri::HTML(open(IMAGES_URL)).css('a').each do |link|
image_names << link.content.strip if link.content.include? '.png'
end
puts 'Retrieving resources...'
image_names.each do |image_name|
puts image_name
File.open("#{image_name}", 'wb') do |fo|
fo.write open("#{IMAGES_URL}#{image_name}").read
end
end
puts 'Zipping files...'
Zip::ZipFile.open('icons.zip', Zip::ZipFile::CREATE) do |zipfile|
image_names.each do |filename|
zipfile.add(filename, filename)
end
end
puts 'Deleting originals...'
image_names.each do |filename|
File.delete(filename)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment