mirror of https://github.com/hrfee/jfa-go
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
4 years ago
|
import subprocess
|
||
|
import shutil
|
||
4 years ago
|
import os
|
||
4 years ago
|
import argparse
|
||
4 years ago
|
from pathlib import Path
|
||
|
|
||
4 years ago
|
parser = argparse.ArgumentParser()
|
||
|
parser.add_argument("-o", "--output", help="output directory for .html and .txt files")
|
||
|
|
||
|
args = parser.parse_args()
|
||
4 years ago
|
|
||
4 years ago
|
def runcmd(cmd):
|
||
4 years ago
|
if os.name == "nt":
|
||
|
return subprocess.check_output(cmd, shell=True)
|
||
4 years ago
|
proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
|
||
|
return proc.communicate()
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
local_path = Path("mail")
|
||
4 years ago
|
|
||
4 years ago
|
for mjml in [f for f in local_path.iterdir() if f.is_file() and "mjml" in f.suffix]:
|
||
|
print(f"Compiling {mjml.name}")
|
||
4 years ago
|
fname = mjml.with_suffix(".html")
|
||
4 years ago
|
runcmd(f"npx mjml {str(mjml)} -o {str(fname)}")
|
||
4 years ago
|
if fname.is_file():
|
||
4 years ago
|
print("Done.")
|
||
4 years ago
|
|
||
4 years ago
|
html = [f for f in local_path.iterdir() if f.is_file() and "html" in f.suffix]
|
||
4 years ago
|
|
||
4 years ago
|
output = Path(args.output) # local_path.parent / "build" / "data"
|
||
|
output.mkdir(parents=True, exist_ok=True)
|
||
4 years ago
|
|
||
|
for f in html:
|
||
4 years ago
|
shutil.copy(str(f), str(output / f.name))
|
||
|
print(f"Copied {f.name} to {str(output / f.name)}")
|
||
|
txtfile = f.with_suffix(".txt")
|
||
4 years ago
|
if txtfile.is_file():
|
||
4 years ago
|
shutil.copy(str(txtfile), str(output / txtfile.name))
|
||
|
print(f"Copied {txtfile.name} to {str(output / txtfile.name)}")
|
||
4 years ago
|
else:
|
||
4 years ago
|
print(
|
||
|
f"Warning: {txtfile.name} does not exist. Text versions of emails should be supplied."
|
||
|
)
|