import datetime import json import os def get_cache_filename(rank_id): # 生成缓存文件名,以年月日+rank_id命名 date_str = datetime.datetime.now().strftime("%Y%m%d") return f"{date_str}_{rank_id}.json" def read_cache(rank_id): # 从缓存文件中读取数据 cache_filename = get_cache_filename(rank_id) if os.path.exists(cache_filename): with open(cache_filename, "r") as file: return json.load(file) return None def write_cache(rank_id, data): # 将数据写入缓存文件 cache_filename = get_cache_filename(rank_id) with open(cache_filename, "w") as file: json.dump(data, file)