aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-11-27 19:09:07 -0600
committerAnthony Wang2020-11-27 19:09:07 -0600
commit4abae31b34c35236115aa994576bd66d7dce3568 (patch)
tree07318b2e8bdd30db117cba62ad488a25f3546da9
parent47e6933a6a142040caa615f524aa6336c5f37385 (diff)
Add backends arg
-rw-r--r--README.md30
-rwxr-xr-x[-rw-r--r--]mkbinder.py19
2 files changed, 44 insertions, 5 deletions
diff --git a/README.md b/README.md
index 3477235..f627a61 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,30 @@
# Astronomy
-Science Olympiad Astronomy
+
+Resources for Science Olympiad Astronomy
+
+## Guide
+
+### Google Drive
+
+Folder: https://drive.google.com/drive/folders/1tSWqSONcjwJWfYled2abuSCmDSUt4KiA?usp=sharing
+
+
+### Generate a binder
+
+You need to have Python 3 installed.
+
+Install dependencies: `pdfkit`, `weasyprint`, `wkhtmltopdf`
+
+Add links to download to text files. The links in each text file will be downloaded to their own folder.
+
+Run `./mkbinder.py`. It may take a while, depending on how many links to download.
+
+```
+usage: mkbinder.py [-h] [--backend {pdfkit,weasyprint}]
+
+optional arguments:
+ -h, --help show this help message and exit
+ --backend {pdfkit,weasyprint}, -b {pdfkit,weasyprint}
+ change the download backend; default: pdfkit
+```
+
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