import pickle
import os

from 查看进度 import visualize_progress


def load_cached_data(file_path):
    """
    从指定的缓存文件加载数据。
    如果文件不存在或加载失败，则返回空字典。
    """
    if not os.path.exists(file_path):
        print(f"Warning: Cache file '{file_path}' does not exist.")
        return {}

    try:
        with open(file_path, 'rb') as f:
            data = pickle.load(f)
            print(f"Successfully loaded cache from '{file_path}'.")
            return data
    except (pickle.UnpicklingError, FileNotFoundError, EOFError) as e:
        print(f"Error loading cache from '{file_path}': {e}")
        return {}


# 示例用法
# data_dct = load_cached_data("G_Firm_add_edges.pkl")

visualize_progress()
