configs.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/usr/bin/env/python
  2. # -*- coding:utf-8 -*-
  3. import logging
  4. import time
  5. import os
  6. import sys
  7. import datetime
  8. class myLog(object):
  9. '''
  10. 封装后的logging
  11. '''
  12. def __init__(self, logger=None, log_cate='my_log'):
  13. '''
  14. 指定保存日志的文件路径,日志级别,以及调用文件
  15. 将日志存入到指定的文件中
  16. '''
  17. # 创建一个logger
  18. self.logger = logging.getLogger(logger)
  19. self.logger.setLevel(logging.INFO) # DEBUG
  20. # 创建一个handler,用于写入日志文件
  21. # self.log_time = time.strftime("%Y_%m_%d")
  22. # file_dir = os.getcwd() + '/../log'
  23. # if not os.path.exists(file_dir):
  24. # os.mkdir(file_dir)
  25. # self.log_path = file_dir
  26. # self.log_name = self.log_path + "/" + log_cate + "." + self.log_time + '.log'
  27. # self.log_name = os.path.join(log_dir, 'parse_log.log') # 日志地址
  28. self.log_name = os.path.join(parse_log_dir, '{}.log'.format(log_cate)) # 日志地址
  29. if os.path.exists(self.log_name): # 设置日志定长自动新建
  30. logsize = os.path.getsize(self.log_name)
  31. if logsize > 180000000: # 180M
  32. os.rename(self.log_name, os.path.join(parse_log_dir, '{}_{}.log'.format(log_cate,
  33. datetime.datetime.now().strftime('%m_%d'))))
  34. # fh = logging.FileHandler(self.log_name, 'a') # 追加模式 这个是python2的
  35. fh = logging.FileHandler(self.log_name, mode='a', encoding='utf8', delay=True)
  36. # fh = logging.FileHandler(self.log_name, 'a', encoding='utf-8') # 这个是python3的
  37. fh.setLevel(logging.INFO)
  38. # 再创建一个handler,用于输出到控制台
  39. # ch = logging.StreamHandler()
  40. # ch.setLevel(logging.INFO)
  41. # 定义handler的输出格式
  42. # formatter = logging.Formatter(
  43. # '[%(asctime)s] %(filename)s->%(funcName)s line:%(lineno)d [%(levelname)s]%(message)s')
  44. # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  45. # formatter = logging.Formatter('{"[%(asctime)s-%(levelname)s-%(filename)s-%(lineno)s]": %(message)s}')
  46. formatter = logging.Formatter('{"host-ip": ' + '"{}"'.format(external_ip)
  47. + ', "log-msg": %(message)s, "other-msg": "%(filename)s-%(lineno)s-%(asctime)s"}')
  48. fh.setFormatter(formatter)
  49. # ch.setFormatter(formatter)
  50. # 给logger添加handler
  51. self.logger.addHandler(fh)
  52. # self.logger.addHandler(ch)
  53. # 添加下面一句,在记录日志之后移除句柄
  54. # self.logger.removeHandler(ch)
  55. # self.logger.removeHandler(fh)
  56. # 关闭打开的文件
  57. fh.close()
  58. # ch.close()
  59. def getlog(self):
  60. return self.logger
  61. class TestingCfg: # testing
  62. internal_ip = '192.168.1.140' # internal
  63. external_ip = '192.168.1.140' # external
  64. server_port = 11066
  65. public_bucket = 'zxhx-1302712961' # 桶名称
  66. region = "ap-shanghai" # 存储桶地域
  67. public_bucket_addr = 'zxhx-1302712961.cos.ap-shanghai.myqcloud.com'
  68. FAIL_FOLDER = "F:/zwj/Text_Structure/fail_files"
  69. IMG_FOLDER = "F:/zwj/Text_Structure/img_folder"
  70. RES_FOLDER = "F:/zwj/Text_Structure/res_folder"
  71. parse_log_dir = "F:/zwj/Text_Structure/logs"
  72. raw_img_upload_folder = 'F:/zwj/word_folder'
  73. old_img_ip = "http://192.168.1.140:8800/ser_static"
  74. mathpix_ip = "http://192.168.1.208:8001/segment/formula/"
  75. kps_phy_ip = "http://192.168.1.86:11088/phy_mark_and_connect"
  76. kps_Hmath_ip = "http://192.168.1.192:13356/auto_labels"
  77. repeat_ip = "http://192.168.1.192:8866/api/repeat/subject"
  78. # repeat_ip = "http://82.156.68.22:8888/repeat/subject" # 全学科查重
  79. # repeat_ip = "http://82.156.68.22:8888/api/repeat/subject" # 保存入库查重
  80. # callback_url_taskcheck = "http://zsytk3api.dev.xueping.com/v1/interior-api/record"
  81. callback_url_taskcheck = "http://zsytk3api.testing.xueping.com/v1/interior-api/record"
  82. class ProductionCfg: # production
  83. internal_ip = '0.0.0.0' # internal
  84. external_ip = '82.156.255.225' # external
  85. server_port = 11088
  86. public_bucket = 'zxhx-pro-1302712961' # 桶名称
  87. region = "ap-beijing" # 存储桶地域
  88. public_bucket_addr = 'zxhx-pro-1302712961.cos.ap-beijing.myqcloud.com' # 桶地址
  89. FAIL_FOLDER = "E:/Text_Structure/fail_files"
  90. IMG_FOLDER = "E:/Text_Structure/img_folder"
  91. RES_FOLDER = "E:/Text_Structure/res_folder"
  92. parse_log_dir = "E:/Text_Structure/logs"
  93. raw_img_upload_folder = 'E:/word_uploads'
  94. old_img_ip = "http://82.156.255.225:11086/ser_static"
  95. mathpix_ip = "http://10.19.1.11:7080/segment/formula/"
  96. kps_phy_ip = "http:/49.232.72.198:11088/phy_mark_and_connect"
  97. kps_Hmath_ip = "http://172.16.2.5:13356/auto_labels"
  98. repeat_ip = "http://10.19.1.18:8866/api/repeat/subject"
  99. callback_url_taskcheck = "http://api.tk.zhixinhuixue.com/v1/interior-api/record"
  100. # sys.argv:从控制台窗台运行程序,程序后加参数,以空格隔开,sys.argv[0]即程序本身
  101. config_class = TestingCfg # 没有参数时,默认按测试环境
  102. if len(sys.argv) > 1:
  103. print(sys.argv, sys.argv[0])
  104. print(sys.argv[1])
  105. if sys.argv[1] == 'test':
  106. config_class = TestingCfg
  107. elif sys.argv[1] == 'product':
  108. config_class = ProductionCfg
  109. else:
  110. print('cmd should be: python server.py test')
  111. print('or: python server.py product')
  112. raise ValueError("命令不正确")
  113. server_ip = config_class.internal_ip
  114. external_ip = config_class.external_ip
  115. server_port = config_class.server_port
  116. public_bucket_addr = config_class.public_bucket_addr
  117. public_bucket = config_class.public_bucket
  118. region = config_class.region
  119. parse_log_dir = config_class.parse_log_dir
  120. # 定义结构化失败文件保存路径
  121. FAIL_FOLDER = config_class.FAIL_FOLDER
  122. if not os.path.isdir(FAIL_FOLDER):
  123. os.makedirs(FAIL_FOLDER)
  124. # 定义再结构化文件中新图片(base64)的保存路径及访问目录
  125. IMG_FOLDER = config_class.IMG_FOLDER
  126. if not os.path.isdir(IMG_FOLDER):
  127. os.makedirs(IMG_FOLDER)
  128. # 回调结果保存路径
  129. RES_FOLDER = config_class.RES_FOLDER
  130. if not os.path.isdir(RES_FOLDER):
  131. os.makedirs(RES_FOLDER)
  132. new_img_ip = "http://{0}:{1}/ser_static".format(external_ip, server_port)
  133. old_img_ip = config_class.old_img_ip
  134. RawImg_UploadFolder = config_class.raw_img_upload_folder
  135. mathpix_ip = config_class.mathpix_ip
  136. kps_phy_ip = config_class.kps_phy_ip
  137. kps_Hmath_ip = config_class.kps_Hmath_ip
  138. callback_url_taskcheck = config_class.callback_url_taskcheck
  139. repeat_ip = config_class.repeat_ip
  140. # 注意:
  141. # 单题解析中,线上css_conflict_deal与线下不一样
  142. # 作答类型
  143. answer_type = {"选择题": 1, "填空题": 2, "解答题": 3, "判断题": 4,
  144. "英语作文": 5, "语文作文": 6}