Browse Source

Logging + Try/Catch for file operation

bernhardbuhl 3 years ago
parent
commit
b661bd3bdd
1 changed files with 9 additions and 2 deletions
  1. 9 2
      icopy2xls/__init__.py

+ 9 - 2
icopy2xls/__init__.py

@@ -2,6 +2,9 @@ import sys
 import json
 import xlrd3 as xlrd
 from openpyxl import load_workbook
+from logging import getLogger
+
+logger = getLogger("pyC")
 
 
 class Writer:
@@ -56,8 +59,12 @@ class Mover:
         not in destination file.
         :return:
         """
-        source = self.read_xlsx(self.source_file_path, self.source_sheet)
-        destination = self.read_xlsx(self.destination_file_path, self.destination_sheet)
+        try:
+            source = self.read_xlsx(self.source_file_path, self.source_sheet)
+            destination = self.read_xlsx(self.destination_file_path, self.destination_sheet)
+        except FileNotFoundError as e:
+            logger.critical(f"File not found: {e}")
+            return
         destination_wb = Writer(self.destination_file_path, self.destination_sheet)  # Writer class object used to update existing file
         if add_missing_columns:
             self.add_missing_columns(source, destination, destination_wb)