From 1c76abc59af35931b70b4742038dae0cfe4890d4 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 18 七月 2023 16:28:18 +0800 Subject: [PATCH] 华鑫适配 --- third_data/kpl_data_manager.py | 64 ++++++++++++++++++++++++++++---- 1 files changed, 56 insertions(+), 8 deletions(-) diff --git a/third_data/kpl_data_manager.py b/third_data/kpl_data_manager.py index b7969c9..279b7b2 100644 --- a/third_data/kpl_data_manager.py +++ b/third_data/kpl_data_manager.py @@ -10,9 +10,8 @@ from third_data import kpl_util, kpl_api from third_data.code_plate_key_manager import LimitUpCodesPlateKeyManager, CodesHisReasonAndBlocksManager - # 浠g爜瀵瑰簲鐨勬定鍋滃師鍥犱繚瀛� -from third_data.kpl_util import KPLPlatManager +from third_data.kpl_util import KPLPlatManager, KPLDataType class KPLCodeLimitUpReasonManager: @@ -33,17 +32,16 @@ return dict_ - - class KPLLimitUpDataRecordManager: total_datas = None latest_datas = {} + latest_origin_datas=[] __kplPlatManager = KPLPlatManager() __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() __CodesPlateKeysManager = CodesHisReasonAndBlocksManager() @classmethod - def __load_hist_and_blocks(cls,code): + def __load_hist_and_blocks(cls, code): # 鏈夋暟鎹柊澧烇紝鍔犺浇鍘嗗彶鍘熷洜涓庢澘鍧� his_reasons = cls.get_latest_infos(code, 10, False) his_reasons = set([r[0] for r in his_reasons]) @@ -55,7 +53,6 @@ cls.__CodesPlateKeysManager.set_blocks(code, bs) except Exception as e: pass - @classmethod def save_record(cls, day, records): @@ -70,6 +67,7 @@ code_block_dict[code].add(b) # 璁剧疆娑ㄥ仠鏁版嵁 if records: + cls.latest_origin_datas = records cls.__LimitUpCodesPlateKeyManager.set_today_limit_up([(r[0], r[5]) for r in records]) # 娑ㄥ仠鏁版嵁璁板綍 @@ -212,6 +210,28 @@ return json.loads(lines[0]) return None + # 鑾峰彇鏈�杩戝嚑澶╃殑鏁版嵁锛屾牴鎹棩鏈熷�掑簭杩斿洖 + def get_latest_from_file(self, type, count): + files = os.listdir(constant.CACHE_PATH) + file_name_list = [] + for f in files: + if f[10:] == f"_{type.value}.log": + file_name_list.append((f.split("_")[0], f)) + + file_name_list.sort(key=lambda x: x[0], reverse=True) + file_name_list = file_name_list[:count] + fresults = [] + for file in file_name_list: + path = f"{constant.CACHE_PATH}/{file[1]}" + if not os.path.exists(path): + continue + with open(path, 'r') as f: + lines = f.readlines() + if lines: + fresults.append((file[0], json.loads(lines[0]))) + + return fresults + def save_data(self, type, datas): self.__latest_datas[type] = datas self.__save_in_file(type, datas) @@ -244,6 +264,34 @@ # print(day, list_) +# 鍘嗗彶娑ㄥ仠鍒楄〃 +__limit_up_list_records_dict = {} + + +# 鑾峰彇鏈�杩戝嚑澶╃殑瀹炴椂娑ㄥ仠淇℃伅 +# 杩斿洖鏍煎紡锛圼鏃ユ湡,鏁版嵁]锛� +def get_current_limit_up_data_records(count): + fresults = [] + day = tool.get_now_date_str() + datas = [] + if day in __limit_up_list_records_dict: + datas = __limit_up_list_records_dict[day] + else: + datas = KPLDataManager().get_latest_from_file(KPLDataType.LIMIT_UP, 10) + if datas: + # 淇濆瓨鏁版嵁 + __limit_up_list_records_dict[day] = datas + for i in range(len(datas)): + if datas[i][0] == day: + continue + fresults.append(datas[i]) + if len(fresults) >= count: + break + return fresults + + if __name__ == "__main__": - ds = set(["1", "2", "3"]) - print(ds.pop()) + fresults = get_current_limit_up_data_records(2) + for d in fresults: + print(d) + get_current_limit_up_data_records(2) -- Gitblit v1.8.0