PK_N/1e߉slack2py/__init__.py""" Simple Slack notification python package, currently supports sending notification by webhook. Next Features:- 1) workspace integration 2) send to multiple channels """ import os,sys name = "Python Slack Notification" __version__="1.0.0" # from builtins import input # Python 3 compatibility # add to PYTHONPATH, used by Sphinx doc system sys.path.insert(1, os.path.dirname(__file__)) PKN`slack2py/webhook.pyimport requests,json class setupWebhook(object): def __init__(self, *args): self.finalurl = None if args: if args[0].startswith("http") and "hooks" in args[0]: self.finalurl = args[0] elif len(args) == 3: self.finalurl = "https://hooks.slack.com/services/{}/{}/{}".format( args[0],args[1],args[2]) else: raise ValueError("please pass correct parameter(s)") else: raise ValueError("please pass (correct) parameter(s)") def getColor(self, statuscode): arr_colors = { "success": "#66ff66", "info" : "#00ffcc", "warning" : "#ffff99", "danger" : "#ff4d4d" } try: return arr_colors[statuscode] except KeyError as e: raise KeyError("please provide proper status code") def sendNotification(self, notif_title=None, error_title=None, error=None, status_code="success"): if notif_title is None or error_title is None or error is None or "" in {notif_title,error_title,error}: raise ValueError("Did not get required parameters") status_code = self.getColor(status_code) url=self.finalurl data={"attachments": [ { "color": status_code, "title": notif_title, "fields": [ { "title": error_title, "value": error, "short": False } ] } ]} headers={"Content-Type":"application/json"} try: requests.post(url = url,data = json.dumps(data),headers=headers,timeout=5) except requests.Timeout: raise Exception() except requests.ConnectionError: raise ConnectionError("Connection not established") return "Success!!"PK]N%N44 slack2py-1.0.0.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2019 Dhananjay Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HMuSaslack2py-1.0.0.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,szd&Y)r$[)T&UD"PK!HK!slack2py-1.0.0.dist-info/METADATAM0}}!'4J9yTOb[0vwيv0hE38wa'cykFM@>&ȇl1D')a(qp'Q;˖1f} EIH8tuRn@[89Bi3:^V̾PK!H}GK*slack2py-1.0.0.dist-info/RECORDuνv0@g `: %SAA(<}]wn[%i aťx =&Pqnp'MJ-:*E _Rǝ DHAvX?J+[9Yp;u}<HЗIײ4Y,Nϲr'x*|!ԈO4H~`Eu,P K5[&w6tOsD((Ş:IRmN|c$V $(װ5PK_N/1e߉slack2py/__init__.pyPKN`slack2py/webhook.pyPK]N%N44 lslack2py-1.0.0.dist-info/LICENSEPK!HMuSa slack2py-1.0.0.dist-info/WHEELPK!HK!m slack2py-1.0.0.dist-info/METADATAPK!H}GK*Yslack2py-1.0.0.dist-info/RECORDPK