Fix file type of downloaded files

This commit is contained in:
Klaus-Uwe Mitterer 2017-02-09 00:39:07 +01:00
parent 0d119dadc0
commit ed91c130b8
2 changed files with 10 additions and 6 deletions

View file

@ -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")

View file

@ -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)