| | |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __load_data(cls): |
| | | record_apth = cls.__get_record_path() |
| | | current_path = cls.__get_current_path() |
| | | def __load_data(cls, day=tool.get_now_date_str()): |
| | | record_apth = cls.__get_record_path(day) |
| | | current_path = cls.__get_current_path(day) |
| | | limit_up_records_dict = {} |
| | | limit_up_current_dict = {} |
| | | |
| | | # 获取历史涨停 |
| | | if os.path.exists(record_apth): |
| | | children = os.listdir(record_apth) |
| | |
| | | line = f.readline().strip() |
| | | if line: |
| | | data = json.loads(line) |
| | | cls.limit_up_records_dict[data[0]] = data |
| | | limit_up_records_dict[data[0]] = data |
| | | # 获取实时涨停 |
| | | if os.path.exists(current_path): |
| | | with open(current_path, mode="r") as f: |
| | |
| | | if line: |
| | | datas = json.loads(line) |
| | | for d in datas: |
| | | cls.limit_up_current_dict[d[0]] = d |
| | | limit_up_current_dict[d[0]] = d |
| | | if day == tool.get_now_date_str(): |
| | | cls.limit_up_records_dict = limit_up_records_dict |
| | | cls.limit_up_current_dict = limit_up_current_dict |
| | | return limit_up_records_dict, limit_up_current_dict |
| | | |
| | | def __save_data(self, limit_up_datas): |
| | | record_path = self.__get_record_path() |
| | |
| | | # 保存文件 |
| | | threading.Thread(target=self.__save_data, args=(limit_up_datas,), daemon=True).start() |
| | | |
| | | def get_limit_up_current_datas(self): |
| | | temps = [self.limit_up_current_dict[k] for k in self.limit_up_current_dict] |
| | | def get_limit_up_current_datas(self, day=tool.get_now_date_str()): |
| | | if day == tool.get_now_date_str(): |
| | | temps = [self.limit_up_current_dict[k] for k in self.limit_up_current_dict] |
| | | else: |
| | | records, current = self.__load_data(day) |
| | | temps = [current[k] for k in current] |
| | | temps.sort(key=lambda x: x[2], reverse=True) |
| | | return temps |
| | | |
| | | def get_limit_up_history_datas(self): |
| | | temps = [self.limit_up_records_dict[k] for k in self.limit_up_records_dict] |
| | | def get_limit_up_history_datas(self, day=tool.get_now_date_str()): |
| | | if day == tool.get_now_date_str(): |
| | | temps = [self.limit_up_records_dict[k] for k in self.limit_up_records_dict] |
| | | else: |
| | | records, current = self.__load_data(day) |
| | | temps = [records[k] for k in records] |
| | | temps.sort(key=lambda x: x[2], reverse=True) |
| | | return temps |
| | | |