-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (55 loc) · 1.98 KB
/
Copy pathmain.py
File metadata and controls
72 lines (55 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import glob
import logging
import os
import shutil
from pathlib import Path
from PIL import Image
import logging_config
from config import CONFIG
from document import Document
from log_messaging import comp_compl, comp_start
logging_config = logging_config.config_logging()
logger = logging.getLogger(__name__)
def read_files() -> list[Path]:
input_path = CONFIG.paths.input_path
logger.info(comp_start(f"Reading all Files in '{input_path}'"))
files = glob.glob(f"{input_path}*")
paths = [Path(f) for f in files if Path(f).is_file()]
logger.info(comp_compl(f"Reading all Files in '{input_path}'"))
return paths
def clear_folder(folder: str) -> None:
logger.info(comp_start(f"Clearing folder '{folder}'"))
for filename in os.listdir(folder):
file_path = os.path.join(folder, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
logger.error((f"Failed to delete {file_path}. Reason: {e}"))
logger.info(comp_compl(f"Clearing folder '{folder}'"))
def copy_and_save_file(source_file: Path, destination_file_name: str):
pass # TODO implement
def analyze_files(files):
logger.info(comp_start("Analyzing all Files"))
for file in files:
clear_folder(CONFIG.paths.temp_path)
d = Document(source_file=file)
d.run_matching()
d.export()
logger.info(comp_compl("Analyzing all Files"))
def main():
logger.info(comp_start("Initializing"))
# Initialize PIllow
Image.MAX_IMAGE_PIXELS = 1000000000
logger.info(comp_compl("Initializing"))
# Initialize App Settings
if CONFIG.dev_Settings.clear_output:
clear_folder(CONFIG.paths.output_path)
clear_folder(CONFIG.paths.output_ocr_path)
# Read all the files
files = read_files()
analyze_files(files)
if __name__ == "__main__":
main()