Last Updated: February 25, 2016
·
595
· blazeeboy

Download latest images from AWW subreddit

this script will use ruby reddit api gem to browse a subreddit i like named AWW, they post cute pets images, i will browse this subreddit latest posts and will download images to my machine, this script could be applied to any subreddit you want to get image from it, the script could be combined with a previous script of mine to post these images to facebook page and spread the cuteness to the world :D
have fun guys.

Gist : https://github.com/blazeeboy/RubyScripts/tree/master/2014-5-9

#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
require 'open-uri' # we'll need to download image with that
require 'ruby_reddit_api' # gem install ruby_reddit_api

# method will take imgur url and 
# filename to save image to it
def download_imgur( url, filename )
  image = open( "#{url}.jpg" ).read
  File.write("#{filename}.jpg", image)
end

# make me a reddit client please
r = Reddit::Api.new

# browse AWW subreddit
# and download images if their url
# is referencing an imgur link
posts = r.browse("aww")
posts.each.with_index(1) do |r, i|
  puts "Downloading #{i}/#{posts.size}"
  download_imgur r.url, r.id if r.url.include? 'imgur'
end

1 Response
Add your response

Nice :)))

over 1 year ago ·