configs.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. topic_segment_ip = "http://192.168.1.204:10622/math_phy_TopicSegment_predict"
  79. phy_topicType_ip = "http://192.168.1.204:10611/phy_topicType_predict"
  80. # repeaty_ip = "http://82.156.68.22:8888/repeat/subject" # 全学科查重
  81. # repeat_ip = "http://82.156.68.22:8888/api/repeat/subject" # 保存入库查重
  82. # callback_url_taskcheck = "http://zsytk3api.dev.xueping.com/v1/interior-api/record"
  83. callback_url_taskcheck = "http://zsytk3api.testing.xueping.com/v1/interior-api/record"
  84. class ProductionCfg: # production
  85. internal_ip = '0.0.0.0' # internal
  86. external_ip = '82.156.255.225' # external
  87. server_port = 11088
  88. public_bucket = 'zxhx-pro-1302712961' # 桶名称
  89. region = "ap-beijing" # 存储桶地域
  90. public_bucket_addr = 'zxhx-pro-1302712961.cos.ap-beijing.myqcloud.com' # 桶地址
  91. FAIL_FOLDER = "E:/Text_Structure/fail_files"
  92. IMG_FOLDER = "E:/Text_Structure/img_folder"
  93. RES_FOLDER = "E:/Text_Structure/res_folder"
  94. parse_log_dir = "E:/Text_Structure/logs"
  95. raw_img_upload_folder = 'E:/word_uploads'
  96. old_img_ip = "http://82.156.255.225:11086/ser_static"
  97. mathpix_ip = "http://10.19.1.11:7080/segment/formula/"
  98. kps_phy_ip = "http:/49.232.72.198:11088/phy_mark_and_connect"
  99. kps_Hmath_ip = "http://172.16.2.5:13356/auto_labels"
  100. repeat_ip = "http://10.19.1.18:8866/api/repeat/subject"
  101. topic_segment_ip = "http://10.19.1.14:10622/math_phy_TopicSegment_predict"
  102. phy_topicType_ip = "http://10.19.1.6:10611/phy_topicType_predict"
  103. callback_url_taskcheck = "http://api.tk.zhixinhuixue.com/v1/interior-api/record"
  104. # sys.argv:从控制台窗台运行程序,程序后加参数,以空格隔开,sys.argv[0]即程序本身
  105. config_class = TestingCfg # 没有参数时,默认按测试环境
  106. if len(sys.argv) > 1:
  107. print(sys.argv, sys.argv[0])
  108. print(sys.argv[1])
  109. if sys.argv[1] == 'test':
  110. config_class = TestingCfg
  111. elif sys.argv[1] == 'product':
  112. config_class = ProductionCfg
  113. else:
  114. print('cmd should be: python server.py test')
  115. print('or: python server.py product')
  116. raise ValueError("命令不正确")
  117. server_ip = config_class.internal_ip
  118. external_ip = config_class.external_ip
  119. server_port = config_class.server_port
  120. public_bucket_addr = config_class.public_bucket_addr
  121. public_bucket = config_class.public_bucket
  122. region = config_class.region
  123. parse_log_dir = config_class.parse_log_dir
  124. # 定义结构化失败文件保存路径
  125. FAIL_FOLDER = config_class.FAIL_FOLDER
  126. if not os.path.isdir(FAIL_FOLDER):
  127. os.makedirs(FAIL_FOLDER)
  128. # 定义再结构化文件中新图片(base64)的保存路径及访问目录
  129. IMG_FOLDER = config_class.IMG_FOLDER
  130. if not os.path.isdir(IMG_FOLDER):
  131. os.makedirs(IMG_FOLDER)
  132. # 回调结果保存路径
  133. RES_FOLDER = config_class.RES_FOLDER
  134. if not os.path.isdir(RES_FOLDER):
  135. os.makedirs(RES_FOLDER)
  136. new_img_ip = "http://{0}:{1}/ser_static".format(external_ip, server_port)
  137. old_img_ip = config_class.old_img_ip
  138. RawImg_UploadFolder = config_class.raw_img_upload_folder
  139. mathpix_ip = config_class.mathpix_ip
  140. kps_phy_ip = config_class.kps_phy_ip
  141. kps_Hmath_ip = config_class.kps_Hmath_ip
  142. callback_url_taskcheck = config_class.callback_url_taskcheck
  143. repeat_ip = config_class.repeat_ip
  144. topic_segment_ip = config_class.topic_segment_ip
  145. phy_topicType_ip = config_class.phy_topicType_ip
  146. # 注意:
  147. # 单题解析中,线上css_conflict_deal与线下不一样
  148. # 作答类型
  149. answer_type = {"选择题": 1, "填空题": 2, "解答题": 3, "判断题": 4,
  150. "英语作文": 5, "语文作文": 6}