From 274c72ec61d98efd714faaa4b8d99c246188572f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Meyer?= Date: Tue, 19 Mar 2024 16:27:39 +0100 Subject: [PATCH] Update conversion script --- stylesheets/convert.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/stylesheets/convert.py b/stylesheets/convert.py index f7caf1e..01ddbb5 100755 --- a/stylesheets/convert.py +++ b/stylesheets/convert.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -import os, sys, platform, tempfile, subprocess +import os, sys, platform, tempfile, subprocess, json +from urllib import request system = platform.system() if system == "Windows": @@ -14,9 +15,21 @@ print(f"Usage: {sys.argv[0]} FILE", file=sys.stderr) sys.exit(1) -input = sys.argv[1] +path = sys.argv[1] +with open(path) as f: + data = f.read() + tmp_dir = tempfile.gettempdir() output = os.path.join(tmp_dir, "dharma_output.html") -subprocess.run(["curl", "-s", "-F", f"file=@{input}", "-o", output, "https://dharmalekha.info/convert"], check=True) +url = "https://dharmalekha.info/convert" +doc = { + "path": path, + "data": data, +} +req = request.Request(url, json.dumps(doc).encode("UTF-8"), headers={'Content-Type':'application/json'}) +resp = request.urlopen(req) +with open(output, "wb") as f: + f.write(resp.read()) + subprocess.run([browser, output], shell=shell)