from PyPDF2 import PdfMerger
from pathlib import Path


def main(base_dir: str, report_name):
    target = f"{base_dir}/{report_name}_gesamt.pdf"
    Path(target).unlink()
    pdfs = [f for f in Path(base_dir).glob(report_name + '_*.pdf')]

    merger = PdfMerger()

    for pdf in pdfs:
        merger.append(pdf)

    merger.write(target)
    merger.close()


if __name__ == '__main__':
    main('C:\\GlobalCube\\ReportOutput', 'Z.07 Einzelbetrachtung_lfd_Monat')
