Commit 0a43c18c authored by zhougaofeng's avatar zhougaofeng
Browse files

Update common_parse.py

parent cbe2abc6
...@@ -33,13 +33,13 @@ def parse_args(): ...@@ -33,13 +33,13 @@ def parse_args():
args = parser.parse_args() args = parser.parse_args()
return args return args
def process_file(file_path, pdf_ocr, excel_ocr, output_dir,config_path): def process_file(file_path, pdf_ocr, excel_ocr, output_dir):
"""Process a single file for OCR based on its extension.""" """Process a single file for OCR based on its extension."""
try: try:
res = '' res = ''
if file_path.endswith('.pdf'): if file_path.endswith('.pdf'):
res = pdf_ocr.ocr_pdf_client(path=file_path, output_dir=output_dir,config_path=config_path) res = pdf_ocr.ocr_pdf_client(path=file_path, output_dir=output_dir)
elif file_path.endswith('.xls') or file_path.endswith('.xlsx'): elif file_path.endswith('.xls') or file_path.endswith('.xlsx'):
res = excel_ocr.parse(file_path, output_dir) res = excel_ocr.parse(file_path, output_dir)
...@@ -63,17 +63,17 @@ def determine_output_dir(output_dir): ...@@ -63,17 +63,17 @@ def determine_output_dir(output_dir):
return os.path.join(current_working_directory, output_dir) return os.path.join(current_working_directory, output_dir)
return output_dir return output_dir
def process_input(input_path, pdf_ocr, excel_ocr, output_dir,config_path): def process_input(input_path, pdf_ocr, excel_ocr, output_dir):
"""Process the input path, which can be a directory or a single file.""" """Process the input path, which can be a directory or a single file."""
if os.path.isdir(input_path): if os.path.isdir(input_path):
for root, _, files in os.walk(input_path): for root, _, files in os.walk(input_path):
for file in files: for file in files:
file_path = os.path.join(root, file) file_path = os.path.join(root, file)
logger.info(f'正在处理文件: {file_path}') logger.info(f'正在处理文件: {file_path}')
process_file(file_path, pdf_ocr, excel_ocr, output_dir,config_path) process_file(file_path, pdf_ocr, excel_ocr, output_dir)
else: else:
logger.info(f'正在处理单个文件: {input_path}') logger.info(f'正在处理单个文件: {input_path}')
process_file(input_path, pdf_ocr, excel_ocr, output_dir,config_path) process_file(input_path, pdf_ocr, excel_ocr, output_dir)
def main(): def main():
args = parse_args() args = parse_args()
...@@ -88,7 +88,7 @@ def main(): ...@@ -88,7 +88,7 @@ def main():
logger.info(f'输入目录或文件的路径为: {input_path}') logger.info(f'输入目录或文件的路径为: {input_path}')
logger.info(f'输出目录为: {output_dir}') logger.info(f'输出目录为: {output_dir}')
process_input(input_path, pdf_ocr, excel_ocr, output_dir,args.config_path) process_input(input_path, pdf_ocr, excel_ocr, output_dir)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment