Created
May 3, 2012 17:50
-
-
Save melriffe/2587571 to your computer and use it in GitHub Desktop.
PragPubinator: Script to download PragPub Magazine into your Dropbox folder
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
#! /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