Download script for 73 Magazine.

I found a script for downloading the 73 magazine PDFs from http://www.archive.org on Marxy’s blog. However, this didn’t work with the Python 3.3 interpreter that I have. Luckily, it wasn’t difficult to update it to the new version.

Here it is:

#
# Download script for 73 Magazine.
# Adapted from http://blog.marxy.org
# for use with Python 3.3 by PA1DSP
#

import os
import urllib.request

MONTHS = ('January', 'February', 'March', 'April', 'May', 'June',
          'July', 'August', 'September', 'October', 'November', 'December')

START_YEAR = 1961
END_YEAR = 2003
OUTPUT_DIR = "73 Magazine"
MISSING = ('73 Magazine/73-Magazine-1975_11.pdf',
'73 Magazine/73-Magazine-1975_12.pdf',)


def main():
    if not os.path.exists(OUTPUT_DIR):
        os.mkdir(OUTPUT_DIR)


    for year in range(START_YEAR, END_YEAR + 1):
        for month in range(1,13):
            monthName = MONTHS[month - 1]
            fileName = "%s/73-Magazine-%d_%d.pdf" % (OUTPUT_DIR, year, month)
            if not os.path.exists(fileName) and fileName not in MISSING:
                editionString = "%d-%02d/%02d_%s_%d" % (year, month, month, monthName, year)
                url = "http://www.archive.org/download/73-magazine-%s.pdf" % editionString
                print("Downloading: %s..." % url)
                print("To: %s" % fileName)
                pdfData = urllib.request.urlopen(url).read()
                outFile = open(fileName, "wb")
                outFile.write(pdfData)
                outFile.close()
            else:
                print("Skipping: %s" % fileName)


if __name__ == "__main__":
    main()
Advertisements