Slack Messages不发送' else'堵塞
我正在尝试在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论