Created
September 10, 2014 08:30
-
-
Save gonglexin/1f97c832c7a44c7ccf19 to your computer and use it in GitHub Desktop.
A downloader for http://louie.land/wallpapers/
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
require 'nokogiri' | |
require 'open-uri' | |
require 'fileutils' | |
base_uri = 'http://louie.land/wallpapers' | |
doc = Nokogiri::HTML(open base_uri) | |
uris = [] | |
doc.css('.grid a').each do |link| | |
uris << link | |
end | |
wallpapers_path = './wallpapers' | |
FileUtils.mkdir_p wallpapers_path | |
FileUtils.cd wallpapers_path | |
def download_wallpaper(uri) | |
system "wget #{uri}" | |
end | |
def get_the_wallpaper(uri) | |
wallpapers_base_uri = uri['href'] | |
doc = Nokogiri::HTML(open wallpapers_base_uri) | |
doc.css('table td a').each do |link| | |
download_wallpaper("#{wallpapers_base_uri}#{link['href']}") if link.content.end_with?('Desktop.jpg') | |
end | |
end | |
threads = [] | |
uris.each do |uri| | |
threads << Thread.new do | |
get_the_wallpaper(uri) | |
end | |
end | |
threads.each { |thr| thr.join } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment