Skip to content

Instantly share code, notes, and snippets.

@j05h
Created October 26, 2011 16:14
Show Gist options
  • Save j05h/1316860 to your computer and use it in GitHub Desktop.
Save j05h/1316860 to your computer and use it in GitHub Desktop.
Download the imgur.com images from reddpics.com; Great for wallpapers/screensavers
#!/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
@j05h
Copy link
Author

j05h commented Oct 26, 2011

Usage: ./earthporn.rb

Num pages defaults to 1; subreddit defaults to earthporn.

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