- better loggin system

- adde test case for bad characters
This commit is contained in:
ari committed 2018-11-23 14:43:51 -05:00
1 parent ac49ad1bcf
commit 38f8ca76a6
7 files changed
+95 -58

No files matched your search

Regular → Executable
+13 -6
View File
@@ -1,9 +1,12 @@
#!/usr/bin/env python
import re
import os
import logging
from typing import List
from pdfmajor.converters import convert_file
from xml.etree import ElementTree
from tqdm import tqdm
def rel_path(*arg: List[str]) -> str:
return os.path.join(os.path.dirname(__file__), *arg)
@@ -18,21 +21,25 @@ if not os.path.exists(OUTPUT_FOLDER):
files = os.listdir(INPUT_FOLDER)
TOTAL = len(files)
for idx, file_name in enumerate(files):
waiter = tqdm(enumerate(files), total=TOTAL)
for idx, file_name in waiter:
file_name_no_ext = re.sub(r'\.pdf$',"", file_name)
input_file_path = os.path.join(INPUT_FOLDER, file_name)
output_file_path = os.path.join(OUTPUT_FOLDER, file_name_no_ext + "." + EXT)
if len(file_name) > len(file_name_no_ext):
print(f"processing {file_name} {idx}/{TOTAL}")
waiter.set_description(f"Processing {file_name}")
with open(input_file_path, 'rb') as input_file:
with open(output_file_path, 'wb') as output_file:
convert_file(
input_file=input_file,
output_file=output_file,
out_type=EXT,
debug=True,
debug_level=logging.NOTSET,
)
print(f" > testing format {file_name} {idx}/{TOTAL}")
ElementTree.parse(output_file_path)
print(f"processing {idx+1}/{TOTAL}")
if EXT == 'xml':
waiter.set_description(f" > testing format {file_name}")
ElementTree.parse(output_file_path)
waiter.refresh()
waiter.set_description("Done")
waiter.close()