-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_print.py
More file actions
48 lines (36 loc) · 1.39 KB
/
generate_print.py
File metadata and controls
48 lines (36 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Generate bracket SVG (and optionally PDF).
Usage:
uv run generate.py # SVG only
uv run generate.py --pdf # SVG + PDF
uv run generate.py --open # SVG + open in browser
"""
import argparse
import os
import subprocess
import sys
from bracket_print.draw import draw_bracket
from bracket_print.teams import WORLD_CUP_TEAMS
def main():
parser = argparse.ArgumentParser(description="Generate World Cup bracket")
parser.add_argument("--pdf", action="store_true", help="Also export to PDF")
parser.add_argument("--open", action="store_true", help="Open SVG in default viewer")
parser.add_argument("-o", "--output", default="output/bracket.svg", help="Output SVG path")
args = parser.parse_args()
os.makedirs(os.path.dirname(args.output), exist_ok=True)
output = os.path.abspath(args.output)
svg_path = draw_bracket(WORLD_CUP_TEAMS, filename=output)
print(f"SVG -> {svg_path}")
if args.pdf:
import cairosvg
pdf_path = svg_path.replace(".svg", ".pdf")
cairosvg.svg2pdf(url=svg_path, write_to=pdf_path)
print(f"PDF -> {pdf_path}")
if args.open:
if sys.platform == "win32":
os.startfile(svg_path)
elif sys.platform == "darwin":
subprocess.run(["open", svg_path])
else:
subprocess.run(["xdg-open", svg_path])
if __name__ == "__main__":
main()