lifeos / scripts /make_flyer.py
awaisaziz's picture
Add LifeOS: local-first personal assistant on Nemotron-3-Nano-4B
40cf485
Raw
History Blame Contribute Delete
1.84 kB
"""Throwaway dev script: generate data/samples/flyer.pdf with fpdf2.
Usage: pip install fpdf2 && python scripts/make_flyer.py
"""
import os
from fpdf import FPDF
ITEMS = [
("Chicken Thighs", "$2.49/lb"),
("Ground Beef", "$3.99/lb"),
("Eggs 18ct", "$4.49"),
("Chickpeas", "2/$3"),
("Basmati Rice 8lb", "$9.99"),
("Greek Yogurt", "$4.99"),
("Bell Peppers", "$1.29 ea"),
("Spinach", "$2.99"),
("Sweet Potatoes", "99c/lb"),
("Canned Tomatoes", "4/$5"),
("Cheddar Block", "$5.49"),
("Tortillas 10pk", "$2.99"),
("Salmon Fillet", "$8.99/lb"),
("Oats 1kg", "$3.49"),
]
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data", "samples", "flyer.pdf")
def main() -> None:
pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", "B", 24)
pdf.cell(0, 14, "FreshMart Weekly Specials", align="C", new_x="LMARGIN", new_y="NEXT")
pdf.set_font("Helvetica", "", 10)
pdf.cell(0, 6, "Open Mon-Sun 8am - 10pm", align="C", new_x="LMARGIN", new_y="NEXT")
pdf.cell(0, 6, "1234 Maple Street, Toronto ON", align="C", new_x="LMARGIN", new_y="NEXT")
pdf.set_font("Helvetica", "B", 14)
pdf.cell(0, 10, "SALE", align="C", new_x="LMARGIN", new_y="NEXT")
pdf.ln(4)
# 2-column grid
pdf.set_font("Helvetica", "", 12)
col_w = pdf.epw / 2
for i in range(0, len(ITEMS), 2):
for j in range(2):
if i + j < len(ITEMS):
item, price = ITEMS[i + j]
pdf.cell(col_w, 10, f"{item} {price}", border=1)
pdf.ln(10)
pdf.ln(6)
pdf.set_font("Helvetica", "I", 9)
pdf.cell(0, 6, "While quantities last. Page 1", align="C")
os.makedirs(os.path.dirname(OUT), exist_ok=True)
pdf.output(OUT)
print(f"Wrote {os.path.abspath(OUT)}")
if __name__ == "__main__":
main()