Slack Messages不发送' else'堵塞

发布于 2025-01-30 11:57:00 字数 1808 浏览 1 评论 0原文

我正在尝试在Slack上发送一条消息,以澄清文件的名称与CSV单元格中的名称匹配。

我遇到的问题是,该消息不会发送else块。打印语句的输出是预期的,但我不知道为什么Slack消息不会发送。没有提供错误。

代码和控制台输出以下。

def send_slack_message(message):

    webhook = 'https://hooks.slack.com/services/.....'
    message = {
        "text": f"{message}",
        "blocks":[
            {
                "type": "header",
                "text": {
                    "type": "plain_text",
                    "text": f"{message}"
                }
            }]
    }
    return requests.post(webhook, json.dumps(message))


def validate_names(path):

    saved_names = os.listdir(path)

    csv_files = glob.glob(os.path.join(path, "*.csv"))

    cell_names = []
    # loop over the list of csv files
    for f in csv_files:
        # read the csv file
        df = pd.read_csv(f, sep=",", on_bad_lines='skip', header=None)
        myMatrix = df[df.columns[0]].to_numpy()
        cell_names.extend(myMatrix.tolist())

    cell_names_csv = list(map(lambda x: x +'.csv', cell_names))
    joined_lists = dict(zip(saved_names, cell_names_csv))

    failed_list = [key for i, key in enumerate(list(joined_lists.keys())) if key != list(joined_lists.values())[i]]

    if list(joined_lists.keys()) == list(joined_lists.values()):
        print(f"Names are good in: {path}")
        send_slack_message(f"Names are good in: {path}")
    else:
        print(f"These names need fixing: {', '.join(failed_list)} || path: {path}")
        send_slack_message(f"These names need fixing: {', '.join(failed_list)} || path: {path}")

validate_names('C:\\Users\\path\\to\\dir')
validate_names('C:\\Users\\path\\to\\dir')

控制台输出:

这些名称需要修复:Weekly_Report_67483.csv,Weekly_report_49385.csv ||路径:'c:\ users \ path \ to \ dir' 名称很好:'c:\ users \ path \ to \ dir'

I'm trying to send myself a message on Slack to clarify that the names of the file match the names in the csv cell.

The issue I'm having is that the message does not send for the else block. The output from the print statement is as expected, but I don't know why the Slack message does not send. No errors are provided.

Code and console output below.

def send_slack_message(message):

    webhook = 'https://hooks.slack.com/services/.....'
    message = {
        "text": f"{message}",
        "blocks":[
            {
                "type": "header",
                "text": {
                    "type": "plain_text",
                    "text": f"{message}"
                }
            }]
    }
    return requests.post(webhook, json.dumps(message))


def validate_names(path):

    saved_names = os.listdir(path)

    csv_files = glob.glob(os.path.join(path, "*.csv"))

    cell_names = []
    # loop over the list of csv files
    for f in csv_files:
        # read the csv file
        df = pd.read_csv(f, sep=",", on_bad_lines='skip', header=None)
        myMatrix = df[df.columns[0]].to_numpy()
        cell_names.extend(myMatrix.tolist())

    cell_names_csv = list(map(lambda x: x +'.csv', cell_names))
    joined_lists = dict(zip(saved_names, cell_names_csv))

    failed_list = [key for i, key in enumerate(list(joined_lists.keys())) if key != list(joined_lists.values())[i]]

    if list(joined_lists.keys()) == list(joined_lists.values()):
        print(f"Names are good in: {path}")
        send_slack_message(f"Names are good in: {path}")
    else:
        print(f"These names need fixing: {', '.join(failed_list)} || path: {path}")
        send_slack_message(f"These names need fixing: {', '.join(failed_list)} || path: {path}")

validate_names('C:\\Users\\path\\to\\dir')
validate_names('C:\\Users\\path\\to\\dir')

Console output:

These names need fixing: weekly_report_67483.csv, weekly_report_49385.csv || path: 'C:\Users\path\to\dir'
Names are good in: 'C:\Users\path\to\dir'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文