aboutsummaryrefslogtreecommitdiff
path: root/mkbinder.py
diff options
context:
space:
mode:
authorAnthony Wang2020-11-27 19:09:07 -0600
committerAnthony Wang2020-11-27 19:09:07 -0600
commit4abae31b34c35236115aa994576bd66d7dce3568 (patch)
tree07318b2e8bdd30db117cba62ad488a25f3546da9 /mkbinder.py
parent47e6933a6a142040caa615f524aa6336c5f37385 (diff)
Add backends arg
Diffstat (limited to 'mkbinder.py')
-rwxr-xr-x[-rw-r--r--]mkbinder.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/mkbinder.py b/mkbinder.py
index 2c02ef5..59bfccb 100644..100755
--- a/mkbinder.py
+++ b/mkbinder.py
@@ -1,7 +1,16 @@
+#!/usr/bin/python3
import pdfkit
-# import weasyprint
+import weasyprint
import re
import os
+import argparse
+
+
+# CLI arguments
+parser = argparse.ArgumentParser()
+parser.add_argument('--backend', '-b', dest = 'backend', help = 'change the download backend; default: pdfkit', default = 'pdfkit', choices = ['pdfkit', 'weasyprint'])
+args = parser.parse_args()
+
for filename in os.listdir("."):
if not filename.endswith(".txt"): continue
@@ -22,9 +31,11 @@ for filename in os.listdir("."):
# print(name)
try:
# weasyprint seems faster?
- pdfkit.from_url(link, name)
- # pdf = weasyprint.HTML(link).write_pdf()
- # open(name, 'wb').write(pdf)
+ if args.backend == 'pdfkit':
+ pdfkit.from_url(link, name)
+ else:
+ pdf = weasyprint.HTML(link).write_pdf()
+ open(name, 'wb').write(pdf)
except:
# Ignore exceptions
# Probably not a good idea