From 2ebd021c7fa32d51122c59ab905dd7f96c5e6a2f Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 9 Feb 2017 21:11:56 +0100 Subject: [PATCH 1/3] Move download logic to helpers.downloadPage() --- falter.py | 6 +----- helpers/__init__.py | 6 ++++++ readit.py | 10 ++-------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/falter.py b/falter.py index 9e5b70c..bb70888 100755 --- a/falter.py +++ b/falter.py @@ -4,11 +4,7 @@ import errno, fpdf, helpers, 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()) - + helpers.downloadPage("https://www.falter.at/falter/e-paper/fetch/%i/%i.jpg" % (issue, page), issue, page) except urllib.error.HTTPError: return False diff --git a/helpers/__init__.py b/helpers/__init__.py index 0ef616c..f8990a7 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py @@ -27,3 +27,9 @@ def makePDF(issue, pages, type = JPG): pdf.output("%s/issue.pdf" % str(issue), "F") +def downloadPage(url, issue, page): + f = urllib.request.urlopen(url) + + with open("%s/%i.png" % (str(issue), int(page)), "b+w") as o: + o.write(f.read()) + diff --git a/readit.py b/readit.py index 54659da..d082e56 100755 --- a/readit.py +++ b/readit.py @@ -47,17 +47,11 @@ def pageHandler(driver, id, page): return False img = driver.find_element_by_id("page1").get_attribute("src") - f = urllib.request.urlopen(img) - - with open("%s/%i.png" % (id, page), "b+w") as o: - o.write(f.read()) + helpers.downloadPage(img, id, page) try: img2 = driver.find_element_by_id("page2").get_attribute("src") - f2 = urllib.request.urlopen(img2) - - with open("%s/%i.png" % (id, page + 1), "b+w") as o2: - o2.write(f2.read()) + helpers.downloadPage(img2, id, page + 1) return 2 From ef043e9e0ecdf0e622ed779856ce47547fb70928 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 9 Feb 2017 21:12:33 +0100 Subject: [PATCH 2/3] Add selenium requirement --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 744c7fb..5dbae69 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ fpdf +selenium From 95271ab882daf3945240959fe3d2fa12f0157512 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 11 Jul 2017 23:28:25 +0200 Subject: [PATCH 3/3] Fix setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5bd2291..7d15391 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ if os.path.isfile("config.cfg"): config = configparser.RawConfigParser() -config.add_section("Romeo") +config.add_section("Read.it") print('''In the next step, we'll get you connected to Read.it. For this, we will need your username and password. Please note that these will be stored on