convert_test.py 3.0 KB

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