103 lines
2.8 KiB
Python
103 lines
2.8 KiB
Python
from modules.adjust_layout import adjust_layout
|
|
from modules.add_logo import add_logo
|
|
from pathlib import Path
|
|
from modules.add_date import add_date
|
|
from datetime import datetime
|
|
from dateutil.relativedelta import relativedelta # type: ignore
|
|
import argparse
|
|
import fitz # type: ignore
|
|
|
|
def convert_pdf_to_png(pdf_path, output_path, dpi=150):
|
|
doc = fitz.open(pdf_path)
|
|
page = doc.load_page(0)
|
|
pix = page.get_pixmap(dpi=dpi)
|
|
pix.save(output_path)
|
|
doc.close()
|
|
|
|
parser = argparse.ArgumentParser(description="Generate formatted roster")
|
|
parser.add_argument("--month", type=str, help="Override the month/year label (e.g., 'September 2025')")
|
|
args = parser.parse_args()
|
|
|
|
if args.month:
|
|
month_year = args.month.upper()
|
|
else:
|
|
today = datetime.now()
|
|
target = today if today.day < 15 else today + relativedelta(months=1)
|
|
month_year = target.strftime("%B %Y").upper()
|
|
|
|
|
|
# Define paths
|
|
base = Path(__file__).parent
|
|
input_pdf = base / "input/original.pdf"
|
|
shifted_pdf = base / "output/shifted.pdf"
|
|
|
|
# Apply layout adjustment
|
|
adjust_layout(input_pdf, shifted_pdf, shift_amount=100)
|
|
|
|
# Paths
|
|
logo_input = shifted_pdf
|
|
logo_output = base / "output/with_logo.pdf"
|
|
logo_file = base / "assets/logo.png"
|
|
|
|
add_logo(logo_input, logo_output, logo_file, position=(50, -10), scale=0.27)
|
|
|
|
|
|
|
|
# Determine month/year label
|
|
if args.month:
|
|
parts = args.month.strip().split()
|
|
full_month = parts[0].capitalize()
|
|
year = parts[1] if len(parts) > 1 else str(datetime.now().year)
|
|
|
|
# Smart abbreviation
|
|
if len(full_month) > 5:
|
|
month = full_month[:3].upper() # "September" → "SEP"
|
|
else:
|
|
month = full_month.upper() # "June" → "JUNE"
|
|
|
|
month_year = f"{month} {year}"
|
|
else:
|
|
today = datetime.now()
|
|
target = today if today.day < 15 else today + relativedelta(months=1)
|
|
full_month = target.strftime("%B")
|
|
year = target.strftime("%Y")
|
|
|
|
if len(full_month) > 5:
|
|
month = target.strftime("%b").upper()
|
|
else:
|
|
month = full_month.upper()
|
|
|
|
month_year = f"{month} {year}"
|
|
|
|
final_pdf_name = f"{month} {year} Roster.pdf"
|
|
final_pdf_path = base / "output" / final_pdf_name
|
|
final_png_path = final_pdf_path.with_suffix(".png")
|
|
date_output = final_pdf_path
|
|
|
|
# Paths
|
|
date_input = logo_output
|
|
font_file = base / "assets/fonts/Roboto-Variable.ttf"
|
|
|
|
add_date(
|
|
input_path=date_input,
|
|
output_path=date_output,
|
|
month_year=month_year,
|
|
font_path=font_file,
|
|
position=(460, 88),
|
|
font_size=48
|
|
)
|
|
|
|
convert_pdf_to_png(final_pdf_path, final_png_path)
|
|
|
|
final_pdf_name = f"{month} {year} Roster.pdf"
|
|
final_pdf_path = base / "output" / final_pdf_name
|
|
|
|
final_png_name = final_pdf_name.replace(".pdf", ".png")
|
|
final_png_path = base / "output" / final_png_name
|
|
|
|
|
|
# Clean up intermediate PDFs
|
|
for path in [shifted_pdf, logo_output, final_pdf_path]:
|
|
if path.exists():
|
|
path.unlink()
|