Created
March 14, 2016 14:52
-
-
Save danielRomero/95c2594646379f38c73f to your computer and use it in GitHub Desktop.
Download all Octocats (https://octodex.github.com/) to local folder
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions
cd ~/Downloads/
chmod +x octocat_downloader.rb
./octocat_downloader.rb
TODO