Quickly implemented the getter.
This commit is contained in:
parent
16eb5a81c6
commit
6bdd458df3
1 changed files with 61 additions and 0 deletions
61
getter.py
61
getter.py
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import errno, fpdf, os, os.path, PIL, urllib.request
|
||||
|
||||
def getPage(issue, page):
|
||||
try:
|
||||
f = urllib.request.urlopen("https://www.falter.at/falter/e-paper/fetch/%i/%i.jpg" % (issue, page))
|
||||
|
||||
with open("%i/%i.jpg" % (issue, page), "b+w") as o:
|
||||
o.write(f.read())
|
||||
|
||||
except urllib.error.HTTPError:
|
||||
return False
|
||||
|
||||
def makeDir(issue):
|
||||
try:
|
||||
os.makedirs(str(issue))
|
||||
return True
|
||||
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
return False
|
||||
|
||||
def makePDF(issue, pages):
|
||||
cover = PIL.Image.open("%i/1.jpg" % issue)
|
||||
x, y = cover.size
|
||||
|
||||
pdf = fpdf.FPDF(unit = "pt", format = [x, y])
|
||||
|
||||
for page in range(pages):
|
||||
pdf.add_page()
|
||||
pdf.image("%i/%i.jpg" % (issue, page + 1), 0, 0)
|
||||
|
||||
pdf.output("%i/issue.pdf" % issue, "F")
|
||||
|
||||
def getIssue(issue, makepdf = True):
|
||||
if makeDir(issue):
|
||||
i = 1
|
||||
|
||||
while getPage(issue, i) is not False:
|
||||
i += 1
|
||||
|
||||
if i == 1:
|
||||
return False
|
||||
|
||||
if i < 5:
|
||||
print("[NOTICE] Incomplete issue: %i" % issue)
|
||||
|
||||
if makepdf:
|
||||
makePDF(issue, i-1)
|
||||
|
||||
def getterLoop(start = 53):
|
||||
i = start
|
||||
|
||||
while getIssue(i) is not False:
|
||||
i += 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
getterLoop()
|
Loading…
Reference in a new issue