Skip to content

Instantly share code, notes, and snippets.

@melriffe
Created May 3, 2012 17:50
Show Gist options
  • Save melriffe/2587571 to your computer and use it in GitHub Desktop.
Save melriffe/2587571 to your computer and use it in GitHub Desktop.
PragPubinator: Script to download PragPub Magazine into your Dropbox folder
#! /usr/bin/env ruby
# Solution Spike, a down-n-dirty implementation of the desired functionality.
require 'rubygems'
require 'mechanize' # mechanize 2.4
target_directory = "#{ENV['HOME']}/Dropbox/Pragmatic Bookshelf/Magazines" # ruby 1.9
FileUtils.mkdir_p target_directory
# Randy the Gerbil's cousin
billy_the_hamster = Mechanize.new
puts "STARTING..."
1.upto(35) do |issue|
puts "Fetching Issue #{issue}"
surprise = billy_the_hamster.get("http://pragprog.com/magazines/download/#{issue}.epub")
if surprise.class == Mechanize::File
puts "Saving #{surprise.filename}..."
local_filename = "#{target_directory}/#{surprise.filename}"
surprise.save(local_filename) unless File.exists?(local_filename)
else
puts "Unable to download Issue #{issue}"
end
end
puts "FINISHED!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment