Created
October 26, 2011 16:14
-
-
Save j05h/1316860 to your computer and use it in GitHub Desktop.
Download the imgur.com images from reddpics.com; Great for wallpapers/screensavers
This file contains hidden or 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 'rubygems' | |
require 'mechanize' | |
def download path, site | |
url = "http://reddpics.com/moreimages/#{site}/#{path}" | |
agent = Mechanize.new | |
page = agent.get url | |
page.links_with(:href => /i.imgur.com/).map(&:href).uniq.each do |img| | |
uri = URI.parse img | |
file = "." + uri.path | |
if File.exists? file | |
puts "#{file} exists" | |
else | |
puts "Downloading #{img}" | |
`wget #{img}` | |
end | |
end | |
page | |
end | |
path = '10' | |
count = (ARGV.shift || 1).to_i | |
site = (ARGV.shift || 'earthporn') | |
count.times do | |
page = download path, site | |
li = page.search(".//li").first | |
path = li.attributes['after'].value | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: ./earthporn.rb
Num pages defaults to 1; subreddit defaults to earthporn.