Created
December 5, 2012 20:58
-
-
Save thejspr/4219410 to your computer and use it in GitHub Desktop.
Download all PragPub issues from Pragmatic Programmers
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 | |
# encoding: utf-8 | |
require 'open-uri' | |
VALID_FORMATS = ['pdf', 'html', 'mobi', 'epub'] | |
format = ARGV[0] || 'pdf' | |
unless VALID_FORMATS.include?(format) | |
puts "Invalid format. Please use: #{VALID_FORMATS.join(',')} (default: pdf)" | |
exit(1) | |
end | |
system('mkdir -p prag_pub') | |
1.upto(31).each do |issue_no| | |
file_name = "#{issue_no}.#{format}" | |
puts "downloading issue #{file_name}" | |
File.open("prag_pub/#{file_name}", "wb") do |saved_file| | |
open("http://pragprog.com/magazines/download/#{file_name}", 'rb') do |input| | |
saved_file.write(input.read) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment