123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import base64
- import json
- import os
- import random
- import sys
- import time
- from glob import glob
- from multiprocessing import Process
- from bs4 import BeautifulSoup
- sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../")
- from format_convert.utils import get_platform, request_post, get_md5_from_bytes
- from format_convert.convert import to_html
- def test_one(p, from_remote=False):
- start_time = time.time()
- with open(p, "rb") as f:
- file_bytes = f.read()
- file_base64 = base64.b64encode(file_bytes)
- _md5 = get_md5_from_bytes(file_bytes)
- data = {"file": file_base64, "type": p.split(".")[-1], "filemd5": 100}
- if from_remote:
- _url = 'http://121.46.18.113:15010/convert'
- # _url = 'http://192.168.2.103:15010/convert'
- # _url = 'http://192.168.2.102:15011/convert'
- # _url = 'http://172.16.160.65:15010/convert'
- # _url = 'http://127.0.0.1:15010/convert'
- result = json.loads(request_post(_url, data, time_out=10000))
- text_str = ""
- for t in result.get("result_html"):
- text_str += t
- to_html(os.path.dirname(os.path.abspath(__file__)) + "/../result.html",
- text_str)
- else:
- print("only support remote!")
- print(_md5)
- print("result_text", result.get("result_text")[0][:20])
- print("is_success", result.get("is_success"))
- print(time.time()-start_time)
- def test_duplicate(path_list, process_no=None):
- start_time = time.time()
- # random.shuffle(path_list)
- for i in range(10):
- if i % 10 == 0:
- if process_no is not None:
- print("Process", process_no, i*len(path_list), time.time()-start_time)
- else:
- print("Loop", i*len(path_list), time.time()-start_time)
- for p in path_list:
- test_one(p, from_remote=True)
- if __name__ == '__main__':
- if get_platform() == "Windows":
- # file_path = "C:/Users/Administrator/Desktop/test_xls/merge_cell.xlsx"
- # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_Interface/20210609202634853485.xlsx"
- # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_ODPS/1624325845476.pdf"
- # file_path = "C:/Users/Administrator/Downloads/20210508190133924ba.pdf"
- # file_path = "C:/Users/Administrator/Desktop/test_doc/error8.doc"
- # file_path = "C:/Users/Administrator/Desktop/test_image/error10.png"
- file_path = "C:/Users/Administrator/Desktop/test_b_table/error1.png"
- # file_path = "C:/Users/Administrator/Desktop/test_pdf/普通error/error3.pdf"
- # file_path = "C:/save_b_table/0-0895e32470613dd7be1139eefd1342c4.png"
- else:
- file_path = "1660296734009.pdf"
- test_one(file_path, from_remote=True)
- # paths = glob("C:/Users/Administrator/Desktop/test_image/*")
- # for file_path in paths:
- # test_one(file_path, from_remote=True)
- # if get_platform() == "Windows":
- # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623328459080.doc",
- # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/94961e1987d1090e.xls",
- # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/11111111.rar"]
- # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623328459080.doc",
- # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/94961e1987d1090e.xls"]
- # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623423836610.pdf"]
- # file_path_list = ["C:/Users/Administrator/Desktop/error16.jpg"]
- # else:
- # file_path_list = ["1623423836610.pdf"]
- # start_time = time.time()
- # p_list = []
- # for j in range(3):
- # p = Process(target=test_duplicate, args=(file_path_list, j, ))
- # p.start()
- # p_list.append(p)
- # for p in p_list:
- # p.join()
- # print("finish", time.time() - start_time)
- # with open(file_path, 'r') as f:
- # t = f.read()
- # soup = BeautifulSoup(t, 'lxml')
- # print(soup.text)
|