Last active
December 16, 2015 20:10
-
-
Save t2/5490559 to your computer and use it in GitHub Desktop.
Script to pull down images from a resource I found on Reddit
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
# 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