import slackweb
slack = slackweb.Slack(url="Copied webhook URL")
def notify(title, text, color):
attachments = [{"title": title,
"text": text,
"color": color, #good, warning, danger
"footer": "Send from Python",
}]
slack.notify(text=None, attachments=attachments)
notify("test","Good morning","good")
notify("test","Hello","warning")
notify("test","Good evening","danger")
For the syntax of attachments, refer to the following
--Set API on slack side
import requests
import json
def notifyImg(title, imageURL):
files = {'file': open(imageURL, 'rb')}
param = {
'token': "Copyed API token",
'channels':'The name of the channel you want to post',
'filename':"filename",
'title': title,
}
requests.post(url="https://slack.com/api/files.upload",params=param, files=files)
notifyImg("Test image", "test.png ") #imageURL is the file path
In addition to notifying that the experiment was over, I thought it would be nice if you could send me the results as well, so I checked the API of slack, so I summarized it. I'm sorry if I make a mistake.
-Post to slack with Python3 -Summary of how to post images from the program to Slack
Recommended Posts