Thursday, September 13, 2018

Simple Python3 Script To Send a Message to Slack Channel


#!/u01/python3/bin/python3
import urllib.request
import urllib.parse
import time
# prepare your clientid, token and channelid
mesg = { 'clientid':'dkenfeewe','token':'***********','channelid':'*****','text':'' }


 def mesg2slack(mytext):
    """
    send notification mesg to slack channel
    """
    global mesg
    mesg['text']=mytext
    mesgutf = urllib.parse.urlencode(mesg).encode("utf-8")
    slackurl = 'https://test.test.com/push.message'
    req = urllib.request.Request(slackurl, data=mesgutf) # this will make the method "POST"
    resp = urllib.request.urlopen(req)

 mesg2slack( 'Weekly Jira UAT bounce ' +  time.strftime('%D %H:%M:%S',start_time) )
 

No comments: