diff --git a/format.py b/format.py index 1525497..f1e7ba0 100755 --- a/format.py +++ b/format.py @@ -12,6 +12,9 @@ import xml.etree.ElementTree as ET import requests import imb +# A lot of stuff needs to be in the same directory, just chdir +os.chdir(os.path.dirname(os.path.realpath(__file__))) + def iso_code(s: str) -> str: if len(s) != 2: @@ -92,11 +95,11 @@ def get_avatar(url: str, secrets: dict) -> str: if avatar_raster is None: return "" - svg_text = f""" + svg_text = f""" - + - """ @@ -164,9 +167,13 @@ parser.add_argument( help="Skip content, e.g. to make postcard back labels", ) +parser.add_argument( + "-d", "--dont-compile", action="store_true", help="Don't compile to output.pdf" +) + args = parser.parse_args() -root = ET.parse( +cldr_root = ET.parse( f"{os.getenv('CLDR_ROOT')}/share/unicode/cldr/common/main/{args.language}.xml" ) @@ -188,7 +195,7 @@ for row in rows: country = ( [] if row["Country"].lower() == args.origin - else [get_country_name(root, row["Country"]).upper()] + else [get_country_name(cldr_root, row["Country"]).upper()] ) address = row["Address"].split("\n") + country @@ -228,3 +235,8 @@ with open("options.json", "w") as options: "cards": cards, }, ) + +if args.dont_compile: + exit() + +os.execlp("typst", "typst", "compile", args.template, "output.pdf")