fread/falter.py
2017-02-08 23:23:38 +01:00

60 lines
1 KiB
Python
Executable file

#!/usr/bin/env python3
import errno, fpdf, os, os.path, pdftools, 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 getIssue(issue, makepdf = True):
if makeDir(issue):
i = 1
while getPage(issue, i) is not False:
i += 1
if i == 1:
os.rmdir(str(issue))
return False
if i < 5:
print("[NOTICE] Incomplete issue: %i" % issue)
if makepdf:
pdftools.makePDF(issue, i-1)
else:
print("[NOTICE] Skipping issue: %i (already exists)" % issue)
def getterLoop(start = 53):
i = start
j = 0
while j < 5:
if getIssue(i) is False:
j += 1
print("[NOTICE] Skipping issue: %i (not found - %i)" (i, j))
else:
j = 0
i += 1
if __name__ == "__main__":
getterLoop()