aboutsummaryrefslogtreecommitdiff
path: root/mkbinder.py
diff options
context:
space:
mode:
authorAnthony Wang2021-02-24 20:15:41 -0600
committerAnthony Wang2021-02-24 20:15:41 -0600
commit077a18268097db843f500527bd702751af13683a (patch)
treea4fae49d0cc548bc0e3785ffc28ed077b2770655 /mkbinder.py
parent7e80bc30d52b053ed115195a6e0e133bc10b85fe (diff)
Update mkbinder
Diffstat (limited to 'mkbinder.py')
-rwxr-xr-xmkbinder.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/mkbinder.py b/mkbinder.py
index 5bd332d..f8c64d5 100755
--- a/mkbinder.py
+++ b/mkbinder.py
@@ -12,6 +12,7 @@ from datetime import date
# CLI arguments
parser = argparse.ArgumentParser()
parser.add_argument('--backend', '-b', dest = 'backend', help = 'change the download backend; default: pdfkit', default = 'pdfkit', choices = ['pdfkit', 'weasyprint'])
+parser.add_argument('--force', '-f', dest = 'force', help = 'force download all links instead of only the ones that need to be updated; default: False', default = False, choices = [False, True])
args = parser.parse_args()
@@ -23,7 +24,7 @@ for filename in os.listdir("Links"):
try:
os.mkdir(filename[:-4])
- except:
+ except: # I love bad error handling
pass
try:
@@ -49,7 +50,7 @@ for filename in os.listdir("Links"):
old_date = date.fromisoformat("1970-01-01")
- if new_date > old_date:
+ if new_date > old_date or args.force:
print("Downloading: " + link[:-1])
print("Edit date: " + str(new_date))
@@ -58,12 +59,13 @@ for filename in os.listdir("Links"):
# print(name)
try:
# weasyprint seems faster?
+ # but seems to be broken sometimes???
if args.backend == 'pdfkit':
pdfkit.from_url(link, name)
else:
pdf = weasyprint.HTML(link).write_pdf()
open(name, 'wb').write(pdf)
- except:
+ except: # Maybe should handle errors a little bit better?
print("Error when printing")
pass