diff --git a/helpers/__init__.py b/helpers/__init__.py index 2332d8e..0ef616c 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py @@ -1,5 +1,8 @@ import errno, os, PIL, fpdf +JPG = 0 +PNG = 1 + def makeDir(issue): try: os.makedirs(str(issue)) @@ -11,15 +14,16 @@ def makeDir(issue): return False -def makePDF(issue, pages): - cover = PIL.Image.open("%s/1.jpg" % str(issue)) +def makePDF(issue, pages, type = JPG): + ext = "jpg" if type == JPG else "png" + cover = PIL.Image.open("%s/1.%s" % (str(issue), ext)) x, y = cover.size pdf = fpdf.FPDF(unit = "pt", format = [x, y]) for page in range(pages): pdf.add_page() - pdf.image("%s/%i.jpg" % (str(issue), page + 1), 0, 0) + pdf.image("%s/%i.%s" % (str(issue), page + 1, ext), 0, 0) pdf.output("%s/issue.pdf" % str(issue), "F") diff --git a/readit.py b/readit.py index 22f9ac6..3973820 100755 --- a/readit.py +++ b/readit.py @@ -49,14 +49,14 @@ def pageHandler(driver, id, page): img = driver.find_element_by_id("page1").get_attribute("src") f = urllib.request.urlopen(img) - with open("%s/%i.jpg" % (id, page), "b+w") as o: + with open("%s/%i.png" % (id, page), "b+w") as o: o.write(f.read()) try: img2 = driver.find_element_by_id("page2").get_attribute("src") f2 = urllib.request.urlopen(img2) - with open("%s/%i.jpg" % (id, page + 1), "b+w") as o2: + with open("%s/%i.png" % (id, page + 1), "b+w") as o2: o2.write(f2.read()) return 2 @@ -75,7 +75,7 @@ def magazineHandler(driver, id, makepdf = True): val = pageHandler(driver, id, page + 1) if makepdf: - helpers.makePDF(id, page) + helpers.makePDF(id, page, helpers.PNG) else: print("[NOTICE] Skipping issue %s - already exists." % id)