aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-02 22:56:04 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-02 22:56:04 +0200
commitd0e334ca8567da06f11cac7a44696796a6dc06db (patch)
tree381d8f6673943283b99a6b8f67699cb974af9d4b
parent4655e38357017574ba730dbdde7fae73e9b153dd (diff)
squash some bugs
-rwxr-xr-xanki-card-template/bulk-cleanup.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/anki-card-template/bulk-cleanup.py b/anki-card-template/bulk-cleanup.py
index c712c51..f123cf6 100755
--- a/anki-card-template/bulk-cleanup.py
+++ b/anki-card-template/bulk-cleanup.py
@@ -3,6 +3,7 @@ import sys
import os
import re
import io
+import importlib
from math import floor, log10
from time import sleep
from pathlib import Path
@@ -14,13 +15,6 @@ class TrashFileIO(object):
def flush(self): pass
trash_out = TrashFileIO()
-# replace stderr file descriptor with /dev/null
-os.dup2(os.open(os.devnull, os.O_WRONLY), 2)
-
-sys.stdout = trash_out
-import aqt
-sys.stdout = real_stdout
-
def recurseplainify(soup):
output = ""
for el in soup.children:
@@ -32,7 +26,7 @@ def recurseplainify(soup):
output += f"*{recurseplainify(el)}*"
continue
- if el.name == 'ruby':
+ if el.name == 'ruby' and len(el.text) > 0:
output += f'[{el.text}]({el.rt.text})'
continue
@@ -41,10 +35,10 @@ def recurseplainify(soup):
return output
def html2cardtemplate(html):
- soup = BeautifulSoup(html)
+ soup = BeautifulSoup(html, features="lxml")
return recurseplainify(soup)
-def main():
+def main(aqt):
sys.stdout = trash_out
app = aqt._run(sys.argv, False)
sys.stdout = real_stdout
@@ -105,5 +99,12 @@ def main():
sys.stdout = trash_out
if __name__ == "__main__":
- main()
+ # replace stderr file descriptor with /dev/null
+ os.dup2(os.open(os.devnull, os.O_WRONLY), 2)
+
+ sys.stdout = trash_out
+ aqt = importlib.import_module("aqt")
+ sys.stdout = real_stdout
+
+ main(aqt)