Fix file type of downloaded files
This commit is contained in:
parent
0d119dadc0
commit
ed91c130b8
2 changed files with 10 additions and 6 deletions
|
@ -1,5 +1,8 @@
|
||||||
import errno, os, PIL, fpdf
|
import errno, os, PIL, fpdf
|
||||||
|
|
||||||
|
JPG = 0
|
||||||
|
PNG = 1
|
||||||
|
|
||||||
def makeDir(issue):
|
def makeDir(issue):
|
||||||
try:
|
try:
|
||||||
os.makedirs(str(issue))
|
os.makedirs(str(issue))
|
||||||
|
@ -11,15 +14,16 @@ def makeDir(issue):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def makePDF(issue, pages):
|
def makePDF(issue, pages, type = JPG):
|
||||||
cover = PIL.Image.open("%s/1.jpg" % str(issue))
|
ext = "jpg" if type == JPG else "png"
|
||||||
|
cover = PIL.Image.open("%s/1.%s" % (str(issue), ext))
|
||||||
x, y = cover.size
|
x, y = cover.size
|
||||||
|
|
||||||
pdf = fpdf.FPDF(unit = "pt", format = [x, y])
|
pdf = fpdf.FPDF(unit = "pt", format = [x, y])
|
||||||
|
|
||||||
for page in range(pages):
|
for page in range(pages):
|
||||||
pdf.add_page()
|
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")
|
pdf.output("%s/issue.pdf" % str(issue), "F")
|
||||||
|
|
||||||
|
|
|
@ -49,14 +49,14 @@ def pageHandler(driver, id, page):
|
||||||
img = driver.find_element_by_id("page1").get_attribute("src")
|
img = driver.find_element_by_id("page1").get_attribute("src")
|
||||||
f = urllib.request.urlopen(img)
|
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())
|
o.write(f.read())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
img2 = driver.find_element_by_id("page2").get_attribute("src")
|
img2 = driver.find_element_by_id("page2").get_attribute("src")
|
||||||
f2 = urllib.request.urlopen(img2)
|
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())
|
o2.write(f2.read())
|
||||||
|
|
||||||
return 2
|
return 2
|
||||||
|
@ -75,7 +75,7 @@ def magazineHandler(driver, id, makepdf = True):
|
||||||
val = pageHandler(driver, id, page + 1)
|
val = pageHandler(driver, id, page + 1)
|
||||||
|
|
||||||
if makepdf:
|
if makepdf:
|
||||||
helpers.makePDF(id, page)
|
helpers.makePDF(id, page, helpers.PNG)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("[NOTICE] Skipping issue %s - already exists." % id)
|
print("[NOTICE] Skipping issue %s - already exists." % id)
|
||||||
|
|
Loading…
Reference in a new issue