Skip to content

Instantly share code, notes, and snippets.

@danielRomero
Created March 14, 2016 14:52
Show Gist options
  • Save danielRomero/95c2594646379f38c73f to your computer and use it in GitHub Desktop.
Save danielRomero/95c2594646379f38c73f to your computer and use it in GitHub Desktop.
Download all Octocats (https://octodex.github.com/) to local folder
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
require 'etc'
# home user path
home_path = Etc.getpwnam(Etc.getlogin).dir
wallpaper_folder = "#{home_path}/Pictures/wallpapers"
if Dir[wallpaper_folder].empty?
Dir.mkdir(wallpaper_folder)
puts "created folder on #{wallpaper_folder}"
end
page = Nokogiri::HTML(open('https://octodex.github.com/'))
page.css('div.item.list a.preview-image img').each do |image|
image_url = "https://octodex.github.com#{image.attributes['data-src'].to_s}"
open(image_url) {|f|
File.open("#{wallpaper_folder}/#{image.attributes['alt'].to_s}.png", "wb") do |file|
file.puts f.read
end
}
end
@danielRomero
Copy link
Author

Instructions

  1. Download the file and cd ~/Downloads/
  2. chmod +x octocat_downloader.rb
  3. Run the ruby script ./octocat_downloader.rb
  4. Go to your Pictures folder. You will find new folder "wallpapers" with all octocats downloaded

TODO

  1. To include gif and svg images

@SergioCC14
Copy link

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment