import os
import re
import logging

# 获取日志记录器
logger = logging.getLogger(__name__)


def get_final_name(download_dir):
    try:
        # 判断是否生成日报成功，如果成功，则转成html返回前端
        report_name_dict = {}
        if os.listdir(download_dir):
            final_files = os.listdir(download_dir)

            for file in final_files:
                if re.match(r".*简版.*", file):
                    report_name_dict["report_sim_name"] = download_dir + "/" + file
                else:
                    report_name_dict["report_name"] = download_dir + "/" + file

        return report_name_dict["report_sim_name"], report_name_dict["report_name"]

    except FileNotFoundError:
        logger.exception(f"获取最终日报或简报路径失败：{FileNotFoundError}")

    except KeyError:
        logger.exception(f"获取最终日报或简报路径失败：{KeyError}")
