""" 日志分析 """ # 获取不可以下单的原因 import os import constant from utils import tool def get_cant_order_reasons_dict(): file_path = "{}/logs/gp/l2/l2_trade.{}.log".format(constant.get_path_prefix(), tool.get_now_date_str()) dict_ = {} if os.path.exists(file_path): with open(file_path, encoding="utf-8") as f: line = f.readline() while line: if line.find("不可以下单,原因:") > -1: code = line.split("code=")[1][:6] time_ = line.split("|")[0].split(" ")[1][:12] reason = line.split("不可以下单,原因:")[1].strip() dict_[code] = (time_, reason) # print(time_, code, reason) line = f.readline() return dict_ def get_kpl_can_buy_reasons_dict(): file_path = "{}/logs/gp/kpl/kpl_block_can_buy.{}.log".format(constant.get_path_prefix(), tool.get_now_date_str()) dict_ = {} if os.path.exists(file_path): with open(file_path, encoding="utf-8") as f: line = f.readline() while line: if True: code = line.split("code=")[1][:6] time_ = line.split("|")[0].split(" ")[1][:12] reason = line.split(f"code={code}:")[1].strip() dict_[code] = (time_, reason.replace("可以下单", "")) # print(time_, code, reason) line = f.readline() return dict_ if __name__ == "__main__": print(get_kpl_can_buy_reasons_dict())