Skip to content

Instantly share code, notes, and snippets.

@kunalgoyal9
Created December 23, 2021 07:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunalgoyal9/2954f9275876721d3efb837bebe09423 to your computer and use it in GitHub Desktop.
Save kunalgoyal9/2954f9275876721d3efb837bebe09423 to your computer and use it in GitHub Desktop.
This gist takes any parameters as message and sends to the channel
import requests
import sys
import getopt
def send_slack_message(message):
payload = '{"text": "%s"}' % message
response = requests.post("https://hooks.slack.com/services/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",
data = payload)
print(response.text)
def main(argv):
message = ''
try: opts, args = getopt.getopt(argv, "hm:", ["message="])
except getopt.GetoptError:
print("Monitor_balance.py -m <message>")
sys.exit(2)
if len(opts) == 0:
message = "yo"
for opt, arg in opts:
if opt == "-h":
print("Monitor_balance.py -m <message>")
sys.exit()
elif opt in ("-m", "--message"):
message = arg
send_slack_message(message)
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment