2020-08-01 20:20:02 +00:00
|
|
|
import subprocess
|
|
|
|
import shutil
|
2020-08-04 17:24:11 +00:00
|
|
|
import os
|
2021-01-05 18:16:23 +00:00
|
|
|
import argparse
|
2020-08-01 20:20:02 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("-o", "--output", help="output directory for .html and .txt files")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
2020-08-16 13:39:47 +00:00
|
|
|
|
2020-08-01 20:20:02 +00:00
|
|
|
def runcmd(cmd):
|
2020-08-04 17:24:11 +00:00
|
|
|
if os.name == "nt":
|
|
|
|
return subprocess.check_output(cmd, shell=True)
|
2020-08-01 20:20:02 +00:00
|
|
|
proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
|
|
|
|
return proc.communicate()
|
|
|
|
|
2020-08-16 13:39:47 +00:00
|
|
|
|
2020-08-01 20:20:02 +00:00
|
|
|
local_path = Path(__file__).resolve().parent
|
|
|
|
|
2020-08-16 13:39:47 +00:00
|
|
|
for mjml in [f for f in local_path.iterdir() if f.is_file() and "mjml" in f.suffix]:
|
|
|
|
print(f"Compiling {mjml.name}")
|
2020-08-01 20:20:02 +00:00
|
|
|
fname = mjml.with_suffix(".html")
|
2020-10-17 23:57:53 +00:00
|
|
|
runcmd(f"npx mjml {str(mjml)} -o {str(fname)}")
|
2020-08-01 20:20:02 +00:00
|
|
|
if fname.is_file():
|
2020-08-16 13:39:47 +00:00
|
|
|
print("Done.")
|
2020-08-01 20:20:02 +00:00
|
|
|
|
2020-08-16 13:39:47 +00:00
|
|
|
html = [f for f in local_path.iterdir() if f.is_file() and "html" in f.suffix]
|
2020-08-01 20:20:02 +00:00
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
output = Path(args.output) # local_path.parent / "build" / "data"
|
|
|
|
output.mkdir(parents=True, exist_ok=True)
|
2020-08-01 20:20:02 +00:00
|
|
|
|
|
|
|
for f in html:
|
2020-08-16 13:39:47 +00:00
|
|
|
shutil.copy(str(f), str(output / f.name))
|
|
|
|
print(f"Copied {f.name} to {str(output / f.name)}")
|
|
|
|
txtfile = f.with_suffix(".txt")
|
2020-08-01 20:20:02 +00:00
|
|
|
if txtfile.is_file():
|
2020-08-16 13:39:47 +00:00
|
|
|
shutil.copy(str(txtfile), str(output / txtfile.name))
|
|
|
|
print(f"Copied {txtfile.name} to {str(output / txtfile.name)}")
|
2020-08-01 20:20:02 +00:00
|
|
|
else:
|
2020-08-16 13:39:47 +00:00
|
|
|
print(
|
|
|
|
f"Warning: {txtfile.name} does not exist. Text versions of emails should be supplied."
|
|
|
|
)
|