added logging

added split_pdf and merge_pdf with location parameter
This commit is contained in:
Niklas Müller 2024-01-05 17:43:01 +01:00
parent 6cb54c31ba
commit 376fafa171
2 changed files with 80 additions and 9 deletions

View file

@ -1,9 +1,48 @@
from pypdf import PdfReader, PdfWriter
import uuid
import os
import shutil
import datetime as dt
import logging
import sys
from pdf_util.pdf_util import pdf_util
# Setup Logging
logging.basicConfig(
# level=logging.ERROR,
# level=logging.INFO,
level=logging.DEBUG,
format=str(dt.datetime.now()).replace(" ", "_") + " | %(asctime)s [%(levelname)s] %(message)s",
handlers=[
logging.FileHandler("/var/log/" + str(dt.datetime.today().strftime('%Y-%m-%d')) + "_-_pdf_project_manager.log"),
logging.StreamHandler(sys.stdout)
]
)
base_path = "/app/projects/"
class pdf_project_manager:
def __init__(self):
self.uuid = str(uuid.uuid4())
os.makedirs("/app/projects/" + self.uuid, exist_ok=True)
self.pdf_init = False
self.project_name = ""
os.makedirs(base_path + self.uuid, exist_ok=True)
"""
def add_pdf(self, pdf_path):
if self.pdf_init:
shutil.copyfile(pdf_path, base_path + self.uuid + "/complete.pdf")
else:
shutil.copyfile(pdf_path, base_path + self.uuid + "/tmp.pdf")
pdf_util(base_path + self.uuid + "/complete.pdf").merge_pdf_with_and_location(base_path + self.uuid + "/tmp.pdf", base_path + self.uuid + "/tmp_complete.pdf")
shutil.copyfile(base_path + self.uuid + "/tmp_complete.pdf", base_path + self.uuid + "/complete.pdf")
os.remove(base_path + self.uuid + "/tmp_complete.pdf")
os.remove(base_path + self.uuid + "/tmp.pdf")
# Splitt files in all single Pages in Subdirectory...
"""