Skip to content

Commit

Permalink
Update conversion script
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnmmeyer committed Mar 19, 2024
1 parent 1f4a887 commit 274c72e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions stylesheets/convert.py
Original file line number Diff line number Diff line change
@@ -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":
Expand All @@ -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)

0 comments on commit 274c72e

Please sign in to comment.