Skip to content

Commit

Permalink
Merge pull request #707 from sbrunner/fix
Browse files Browse the repository at this point in the history
Add error handling 22fb5b6 - Fix destination file name
  • Loading branch information
sbrunner authored Jul 21, 2022
2 parents 5328493 + 2363532 commit 862dd6d
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions scan_to_paperless/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
import glob
import logging
import math
import os
import re
Expand Down Expand Up @@ -37,6 +38,7 @@

# dither, crop, append, repage
CONVERT = ["gm", "convert"]
LOG_ = logging.getLogger(__name__)


def rotate_image(
Expand Down Expand Up @@ -1183,22 +1185,25 @@ def process_code() -> None:
"""Detect ad add a page with the QR codes."""
for pdf_filename in glob.glob(os.path.join(os.environ.get("SCAN_CODES_FOLDER", "/scan-codes"), "*.pdf")):
destination_filename = os.path.join(
os.environ.get("SCAN_FINAL_FOLDER", "/final"), os.path.basename(pdf_filename)
os.environ.get("SCAN_FINAL_FOLDER", "/destination"), os.path.basename(pdf_filename)
)

if os.path.exists(destination_filename):
continue

code.add_codes(
pdf_filename,
destination_filename,
dpi=float(os.environ.get("SCAN_CODES_DPI", 200)),
pdf_dpi=float(os.environ.get("SCAN_CODES_PDF_DPI", 72)),
font_name=os.environ.get("SCAN_CODES_FONT_NAME", "Helvetica-Bold"),
font_size=float(os.environ.get("SCAN_CODES_FONT_SIZE", 16)),
margin_top=float(os.environ.get("SCAN_CODES_MARGIN_TOP", 0)),
margin_left=float(os.environ.get("SCAN_CODES_MARGIN_LEFT", 2)),
)
try:
code.add_codes(
pdf_filename,
destination_filename,
dpi=float(os.environ.get("SCAN_CODES_DPI", 200)),
pdf_dpi=float(os.environ.get("SCAN_CODES_PDF_DPI", 72)),
font_name=os.environ.get("SCAN_CODES_FONT_NAME", "Helvetica-Bold"),
font_size=float(os.environ.get("SCAN_CODES_FONT_SIZE", 16)),
margin_top=float(os.environ.get("SCAN_CODES_MARGIN_TOP", 0)),
margin_left=float(os.environ.get("SCAN_CODES_MARGIN_LEFT", 2)),
)
except Exception as e:
LOG_.exception(f"Error while processing {pdf_filename}: {e}")


def is_sources_present(images: List[str], root_folder: str) -> bool:
Expand Down

0 comments on commit 862dd6d

Please # to comment.