convert_test.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import base64
  2. import json
  3. import os
  4. import random
  5. import sys
  6. import time
  7. from multiprocessing.context 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.103:15010/convert'
  20. # _url = 'http://172.16.160.65:15010/convert'
  21. result = json.loads(request_post(_url, data, time_out=10000))
  22. else:
  23. print("only support remote!")
  24. print(_md5)
  25. print("result_text", result.get("result_text")[0][:20])
  26. print("is_success", result.get("is_success"))
  27. print(time.time()-start_time)
  28. def test_duplicate(path_list, process_no=None):
  29. start_time = time.time()
  30. # random.shuffle(path_list)
  31. for i in range(1):
  32. if i % 10 == 0:
  33. if process_no is not None:
  34. print("Process", process_no, i*len(path_list), time.time()-start_time)
  35. else:
  36. print("Loop", i*len(path_list), time.time()-start_time)
  37. for p in path_list:
  38. test_one(p, from_remote=True)
  39. if __name__ == '__main__':
  40. if get_platform() == "Windows":
  41. # file_path = "C:/Users/Administrator/Desktop/error2.swf"
  42. # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_Interface/20210609202634853485.xlsx"
  43. # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_ODPS/1624325845476.pdf"
  44. file_path = "C:/Users/Administrator/Downloads/1652672734044.jpg"
  45. else:
  46. file_path = "test1.doc"
  47. test_one(file_path, from_remote=True)
  48. # if get_platform() == "Windows":
  49. # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623328459080.doc",
  50. # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/94961e1987d1090e.xls",
  51. # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/11111111.rar"]
  52. # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623328459080.doc",
  53. # # "D:/BIDI_DOC/比地_文档/2022/Test_Interface/94961e1987d1090e.xls"]
  54. # # file_path_list = ["D:/BIDI_DOC/比地_文档/2022/Test_Interface/1623423836610.pdf"]
  55. # file_path_list = ["C:/Users/Administrator/Downloads/广东中检达元检测技术有限公司.pdf",
  56. # "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)