convert_test.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import base64
  2. import json
  3. import os
  4. import random
  5. import sys
  6. import time
  7. from multiprocessing import Process
  8. sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../")
  9. from format_convert.utils import get_platform, request_post, get_md5_from_bytes
  10. from format_convert.convert import to_html
  11. def test_one(p, from_remote=False):
  12. start_time = time.time()
  13. with open(p, "rb") as f:
  14. file_bytes = f.read()
  15. file_base64 = base64.b64encode(file_bytes)
  16. _md5 = get_md5_from_bytes(file_bytes)
  17. data = {"file": file_base64, "type": p.split(".")[-1], "filemd5": 100}
  18. if from_remote:
  19. _url = 'http://121.46.18.113:15010/convert'
  20. # _url = 'http://192.168.2.103:15010/convert'
  21. # _url = 'http://172.16.160.65:15010/convert'
  22. # _url = 'http://127.0.0.1:15010/convert'
  23. result = json.loads(request_post(_url, data, time_out=10000))
  24. text_str = ""
  25. for t in result.get("result_html"):
  26. text_str += t
  27. to_html(os.path.dirname(os.path.abspath(__file__)) + "/../result.html",
  28. text_str)
  29. else:
  30. print("only support remote!")
  31. print(_md5)
  32. print("result_text", result.get("result_text")[0][:20])
  33. print("is_success", result.get("is_success"))
  34. print(time.time()-start_time)
  35. def test_duplicate(path_list, process_no=None):
  36. start_time = time.time()
  37. # random.shuffle(path_list)
  38. for i in range(10):
  39. if i % 10 == 0:
  40. if process_no is not None:
  41. print("Process", process_no, i*len(path_list), time.time()-start_time)
  42. else:
  43. print("Loop", i*len(path_list), time.time()-start_time)
  44. for p in path_list:
  45. test_one(p, from_remote=True)
  46. if __name__ == '__main__':
  47. if get_platform() == "Windows":
  48. # file_path = "C:/Users/Administrator/Desktop/test_xls/merge_cell.xlsx"
  49. # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_Interface/20210609202634853485.xlsx"
  50. # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_ODPS/1624325845476.pdf"
  51. file_path = "C:/Users/Administrator/Downloads/1653559902461.pdf"
  52. else:
  53. file_path = "test1.doc"
  54. test_one(file_path, from_remote=True)
  55. # if get_platform() == "Windows":
  56. # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623328459080.doc",
  57. # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/94961e1987d1090e.xls",
  58. # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/11111111.rar"]
  59. # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623328459080.doc",
  60. # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/94961e1987d1090e.xls"]
  61. # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623423836610.pdf"]
  62. # file_path_list = ["C:/Users/Administrator/Desktop/error16.jpg"]
  63. # else:
  64. # file_path_list = ["1623423836610.pdf"]
  65. # start_time = time.time()
  66. # p_list = []
  67. # for j in range(3):
  68. # p = Process(target=test_duplicate, args=(file_path_list, j, ))
  69. # p.start()
  70. # p_list.append(p)
  71. # for p in p_list:
  72. # p.join()
  73. # print("finish", time.time() - start_time)