def check_token(self): # 设置刷新时间 if datetime.datetime.now() >= self.target_refresh_time: self.target_refresh_time = datetime.datetime.now( ) + datetime.timedelta(minutes=1) self.using_time = 5 self.token_index = 0 self.using_token = self.tokens[self.token_index] ts.set_token(self.using_token) else: using_time = self.using_time - 1 if using_time == 0: using_time = 5 self.token_index += 1 self.using_token = self.tokens[self.token_index] ts.set_token(self.using_token) self.using_time = using_time if self.token_index >= len(self.tokens): tmc.tm_print('token已经使用完毕') return False # print('using_token:{}\nusing_time:{}\ntargte_refresh_tim:{}\ntoken_index:{}' # .format(self.using_token,self.using_time,self.target_refresh_time,self.token_index)) return True
def saveTasksJsonFile(ts_code, tasks_arr): filepath = tmc.get_json_path() tasks_dic = {} if os.path.exists(filepath): tasks_dic = readJsonFile(filepath) tasks_dic[ts_code] = tasks_arr saveJsonFile(filepath, tasks_dic)
def connect_db(self): conf_dict = tmc.get_mysql_config_dict() # 连接数据库 host = conf_dict['host'] port = int(conf_dict['port']) user = conf_dict['user'] password = conf_dict['password'] db_name = conf_dict['db'] self.g_connection = pymysql.connect( port=port, host=host, user=user, password=password, # db='demo', charset='utf8') cursor = self.g_connection.cursor() sql_create_db_cmd = 'CREATE DATABASE IF NOT EXISTS {};'.format(db_name) sql_use_db = 'USE {};'.format(db_name) try: cursor.execute(sql_create_db_cmd) cursor.execute(sql_use_db) except Exception as msg: tm_print(msg)
def readTaskJsonFile(ts_code): path = tmc.get_json_path() task_dic = readJsonFile(path) tasks = task_dic[ts_code] return tasks
def get_token(self): tokens = tmc.get_ts_tokens() return tokens