<commit_before>#!/usr/bin/env python

"""
Generates an Art Mart Inventory Sheet.

sudo apt-get install python-reportlab

Best reportlab reference is the ReportLab User's Guide.
"""

import csv
import datetime
import optparse
import reportlab.lib
import reportlab.platypus

INCH = reportlab.lib.units.inch
BLACK = reportlab.lib.colors.black

class NumberedCanvas(reportlab.pdfgen.canvas.Canvas):
    """http://code.activestate.com/recipes/576832/"""
    def __init__(self, *args, **kwargs):
        reportlab.pdfgen.canvas.Canvas.__init__(self, *args, **kwargs)
        self._saved_page_states = []

    def showPage(self):
        self._saved_page_states.append(dict(self.__dict__))
        self._startPage()

    def save(self):
        """add page info to each page (page x of y)"""
        num_pages = len(self._saved_page_states)
        for state in self._saved_page_states:
            self.__dict__.update(state)
            self.draw_page_number(num_pages)
            reportlab.pdfgen.canvas.Canvas.showPage(self)
        reportlab.pdfgen.canvas.Canvas.save(self)

    def draw_page_number(self, page_count):
        self.setFont("Helvetica", 9)
        label_str = "Page %d of %d" % (self._pageNumber, page_count)
        self.drawRightString(8.25 * INCH, 0.50 * INCH, label_str)


def on_page(canvas, doc):
    """Add page header and footer.  Called for each page."""
    today_str = datetime.date.today().isoformat()
    page_width = doc.pagesize[0]
    page_height = doc.pagesize[1]
    canvas.saveState()

    # Title.
    canvas.setFont('Helvetica-Bold', 18)
    canvas.drawCentredString(
        3.65 * INCH,
        page_height - 0.75 * INCH,
        "Art Mart Inventory Sheet"
    )
    canvas.drawCentredString(
        3.65 * INCH,
        page_height - 1.0 * INCH,
        "Check In/Out"
    )

    # Upper-right block.
    canvas.setFont('Helvetica', 10)
    canvas.drawString(6.65 * INCH, page_height - 0.60 * INCH, "Office Use Only")
    canvas.setFont('Helvetica', 9)
    canvas.drawRightString(7.15 * INCH, page_height - 0.80 * INCH, "Recd. Via")
    canvas.drawRightString(7.15 * INCH, page_height - 1.00 * INCH, "Date Recd")
    canvas.drawString(7.25 * INCH, page_height - 0.80 * INCH, "_________")
    canvas.drawString(7.25 * INCH, page_height - 1.00 * INCH, "_________")

    # Second block.
    canvas.setFont('Helvetica-Bold', 12)
    canvas.drawRightString(1.65 * INCH, page_height - 1.45 * INCH, "Artist #")
    canvas.drawRightString(1.65 * INCH, page_height - 1.75 * INCH, "Store")
    canvas.drawRightString(3.15 * INCH, page_height - 1.45 * INCH, "Artist")
    canvas.drawRightString(3.15 * INCH, page_height - 1.75 * INCH, "Email")
    canvas.drawRightString(6.75 * INCH, page_height - 1.45 * INCH, "Date")
    canvas.drawRightString(6.75 * INCH, page_height - 1.75 * INCH, "Phone")
    canvas.setFont('Helvetica', 12)
    email = "<EMAIL>"
    canvas.drawString(1.75 * INCH, page_height - 1.45 * INCH, "2587")
    canvas.drawString(1.75 * INCH, page_height - 1.75 * INCH, "Boulder")
    canvas.drawString(3.25 * INCH, page_height - 1.45 * INCH, "<NAME>")
    canvas.drawString(3.25 * INCH, page_height - 1.75 * INCH, email)
    canvas.drawString(6.85 * INCH, page_height - 1.45 * INCH, today_str)
    canvas.drawString(6.85 * INCH, page_height - 1.75 * INCH, "720.318.4099")

    # Bottom block.
    canvas.setFont('Helvetica', 9)
    canvas.drawCentredString(
        page_width / 2.0,
        1.35 * INCH,
        "All checkin and out sheets should be signed below after being" +
        " verified by the Artist and an Art Mart Employee"
    )
    canvas.drawRightString(1.45 * INCH, 0.98 * INCH, "Signed")
    sig_line = "____________________________________________"
    canvas.drawString(1.55 * INCH, 0.98 * INCH, sig_line)
    canvas.drawString(4.80 * INCH, 0.98 * INCH, sig_line)
    canvas.drawCentredString(3.00 * INCH, 0.80 * INCH, "Art Mart Employee")
    canvas.drawCentredString(
        6.10 * INCH,
        0.80 * INCH,
        "Artist or Representative"
    )

    # Footer.
    canvas.setFont('Helvetica', 9)
    canvas.drawString(
        0.25 * INCH,
        0.50 * INCH,
        "Revised: %s" % today_str
    )

    canvas.restoreState()


def generate_pdf(products, quantities, pdf_filename):
    """Generate the PDF file."""
    # Construct a document.
    doc = reportlab.platypus.BaseDocTemplate(
        pdf_filename,
        pagesize=reportlab.lib.pagesizes.letter,
        title="Art Mart Inventory Sheet Check In/Out",
        #showBoundary=True
    )

    # Construct a frame.
    page_width = doc.pagesize[0]
    page_height = doc.pagesize[1]
    frames = [
        reportlab.platypus.Frame(
            id="table_frame",
            x1=0.25 * INCH,<commit_msg>gen-art-mart-checkin.py: remove redundant date footer<commit_after>#!/usr/bin/env python

"""
Generates an Art Mart Inventory Sheet.

sudo apt-get install python-reportlab

Best reportlab reference is the ReportLab User's Guide.
"""

import csv
import datetime
import optparse
import reportlab.lib
import reportlab.platypus

INCH = reportlab.lib.units.inch
BLACK = reportlab.lib.colors.black

class NumberedCanvas(reportlab.pdfgen.canvas.Canvas):
    """http://code.activestate.com/recipes/576832/"""
    def __init__(self, *args, **kwargs):
        reportlab.pdfgen.canvas.Canvas.__init__(self, *args, **kwargs)
        self._saved_page_states = []

    def showPage(self):
        self._saved_page_states.append(dict(self.__dict__))
        self._startPage()

    def save(self):
        """add page info to each page (page x of y)"""
        num_pages = len(self._saved_page_states)
        for state in self._saved_page_states:
            self.__dict__.update(state)
            self.draw_page_number(num_pages)
            reportlab.pdfgen.canvas.Canvas.showPage(self)
        reportlab.pdfgen.canvas.Canvas.save(self)

    def draw_page_number(self, page_count):
        self.setFont("Helvetica", 9)
        label_str = "Page %d of %d" % (self._pageNumber, page_count)
        self.drawRightString(8.25 * INCH, 0.50 * INCH, label_str)


def on_page(canvas, doc):
    """Add page header and footer.  Called for each page."""
    today_str = datetime.date.today().isoformat()
    page_width = doc.pagesize[0]
    page_height = doc.pagesize[1]
    canvas.saveState()

    # Title.
    canvas.setFont('Helvetica-Bold', 18)
    canvas.drawCentredString(
        3.65 * INCH,
        page_height - 0.75 * INCH,
        "Art Mart Inventory Sheet"
    )
    canvas.drawCentredString(
        3.65 * INCH,
        page_height - 1.0 * INCH,
        "Check In/Out"
    )

    # Upper-right block.
    canvas.setFont('Helvetica', 10)
    canvas.drawString(6.65 * INCH, page_height - 0.60 * INCH, "Office Use Only")
    canvas.setFont('Helvetica', 9)
    canvas.drawRightString(7.15 * INCH, page_height - 0.80 * INCH, "Recd. Via")
    canvas.drawRightString(7.15 * INCH, page_height - 1.00 * INCH, "Date Recd")
    canvas.drawString(7.25 * INCH, page_height - 0.80 * INCH, "_________")
    canvas.drawString(7.25 * INCH, page_height - 1.00 * INCH, "_________")

    # Second block.
    canvas.setFont('Helvetica-Bold', 12)
    canvas.drawRightString(1.65 * INCH, page_height - 1.45 * INCH, "Artist #")
    canvas.drawRightString(1.65 * INCH, page_height - 1.75 * INCH, "Store")
    canvas.drawRightString(3.15 * INCH, page_height - 1.45 * INCH, "Artist")
    canvas.drawRightString(3.15 * INCH, page_height - 1.75 * INCH, "Email")
    canvas.drawRightString(6.75 * INCH, page_height - 1.45 * INCH, "Date")
    canvas.drawRightString(6.75 * INCH, page_height - 1.75 * INCH, "Phone")
    canvas.setFont('Helvetica', 12)
    email = "<EMAIL>"
    canvas.drawString(1.75 * INCH, page_height - 1.45 * INCH, "2587")
    canvas.drawString(1.75 * INCH, page_height - 1.75 * INCH, "Boulder")
    canvas.drawString(3.25 * INCH, page_height - 1.45 * INCH, "<NAME>")
    canvas.drawString(3.25 * INCH, page_height - 1.75 * INCH, email)
    canvas.drawString(6.85 * INCH, page_height - 1.45 * INCH, today_str)
    canvas.drawString(6.85 * INCH, page_height - 1.75 * INCH, "720.318.4099")

    # Bottom block.
    canvas.setFont('Helvetica', 9)
    canvas.drawCentredString(
        page_width / 2.0,
        1.35 * INCH,
        "All checkin and out sheets should be signed below after being" +
        " verified by the Artist and an Art Mart Employee"
    )
    canvas.drawRightString(1.45 * INCH, 0.98 * INCH, "Signed")
    sig_line = "____________________________________________"
    canvas.drawString(1.55 * INCH, 0.98 * INCH, sig_line)
    canvas.drawString(4.80 * INCH, 0.98 * INCH, sig_line)
    canvas.drawCentredString(3.00 * INCH, 0.80 * INCH, "Art Mart Employee")
    canvas.drawCentredString(
        6.10 * INCH,
        0.80 * INCH,
        "Artist or Representative"
    )

    canvas.restoreState()


def generate_pdf(products, quantities, pdf_filename):
    """Generate the PDF file."""
    # Construct a document.
    doc = reportlab.platypus.BaseDocTemplate(
        pdf_filename,
        pagesize=reportlab.lib.pagesizes.letter,
        title="Art Mart Inventory Sheet Check In/Out",
        #showBoundary=True
    )

    # Construct a frame.
    page_width = doc.pagesize[0]
    page_height = doc.pagesize[1]
    frames = [
        reportlab.platypus.Frame(
            id="table_frame",
            x1=0.25 * INCH,
{'fraction_non_alphanumeric': 0.1290495028333155, 'fraction_numerical': 0.04201860365658078, 'mean_word_length': 2.8257668711656443, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4404321', 'n_tokens_mistral': 3482, 'n_tokens_neox': 3218, 'n_words': 696}