Skip to content

Instantly share code, notes, and snippets.

@danielglh
Last active November 1, 2020 21:32
Show Gist options
  • Save danielglh/8f4d4e7bca4975aa9b85cd1957eaaca4 to your computer and use it in GitHub Desktop.
Save danielglh/8f4d4e7bca4975aa9b85cd1957eaaca4 to your computer and use it in GitHub Desktop.
Download All Free PragPub Magazines
# PragPub magazines offer the first 49 issues for free here: https://pragprog.com/magazines.
# This script allows you to download all these free issues.
# For newer issues, you have to purchase them here: http://theprosegarden.com/.
require 'open-uri'
require 'open_uri_redirections'
def download_issue(num)
num = num.to_s.rjust(3, "0")
dir = "issue.#{num}"
Dir.mkdir(dir) unless File.exists?(dir)
%w(pdf html mobi epub).each do |ext|
url = "https://pragprog.com/magazines/download/#{num}.#{ext}"
open("#{dir}/pragpub_#{num}.#{ext}", 'wb') do |file|
file << open(url, allow_redirections: :all).read
end
end
end
(1..49).each {|i| download_issue(i)}
@thepelkus-too
Copy link

Thanks for this! Looks like the urls have changed, and I don't think html versions are available anymore, but I made some changes that did the trick for me (along with changing the local dir structure for my own purposes):

# PragPub magazines offer the first 49 issues for free here: https://pragprog.com/magazines.
# This script allows you to download all these free issues.
# For newer issues, you have to purchase them here: http://theprosegarden.com/.

require 'open-uri'
require 'open_uri_redirections'

def download_issue(num)
  year = 2009 + (num+5)/12
  month = ((num+5).remainder(12) + 1).to_s.rjust(2, "0")
  basename = "pragpub-#{year}-#{month}"
  Dir.mkdir(basename) unless File.exists?(basename)
  %w(pdf mobi epub).each do |ext|
    url = "https://magazines.pragprog.com/#{year}/#{basename}.#{ext}"
    open("#{basename}/#{basename}.#{ext}", 'wb') do |file|
      file << open(url, allow_redirections: :all).read
    end
  end
end

(1..49).each {|i| download_issue(i)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment