Skip to content

Instantly share code, notes, and snippets.

@thejspr
Created December 5, 2012 20:58
Show Gist options
  • Save thejspr/4219410 to your computer and use it in GitHub Desktop.
Save thejspr/4219410 to your computer and use it in GitHub Desktop.
Download all PragPub issues from Pragmatic Programmers
#!/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