Created
November 24, 2012 07:34
-
-
Save techmaniack/4138797 to your computer and use it in GitHub Desktop.
a small ruby script to grab The Pragmatic Programmers Free Magazines (http://pragprog.com/magazines)
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 'open-uri' | |
#wget could have been used but then it would | |
# 1) Make it dependent on an external program | |
# 2) Make it a one-liner ;) | |
# | |
#This script when executed will start downloading all the prag-mags | |
#in the current directory. | |
if ARGV.count == 0 | |
puts "SAMPLE USGAE: $ruby prag_mag_grabber.rb <option>" | |
puts "<option> = PDF | epub | mobi" | |
exit | |
end | |
url ="http://pragprog.com/magazines/download/" | |
type = ARGV[0] | |
40.times do |id| | |
File.open("#{id+1}.#{type}", "wb") do |saved_file| | |
puts("\n Grabbing #{id+1}.#{type} ...") | |
open("#{url}#{id+1}.#{type}", 'rb') do |read_file| | |
saved_file.write(read_file.read) | |
end | |
puts("\n Grabbed and Stored #{id+1}.#{type} \\m/") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment