slacknotification#

slacknotification(message=None, webhook=None, to=None, fromuser=None, verbose=2, die=False)[source]#

Send a Slack notification when something is finished.

The webhook is either a string containing the webhook itself, or a plain text file containing a single line which is the Slack webhook. By default it will look for the file “.slackurl” in the user’s home folder. The webhook needs to look something like “https://hooks.slack.com/services/af7d8w7f/sfd7df9sb/lkcpfj6kf93ds3gj”. Webhooks are effectively passwords and must be kept secure! Alternatively, you can specify the webhook in the environment variable SLACKURL.

Parameters:
  • message (str) – The message to be posted.

  • webhook (str) – See above

  • to (str) – The Slack channel or user to post to. Channels begin with #, while users begin with @ (note: ignored by new-style webhooks)

  • fromuser (str) – The pseudo-user the message will appear from (note: ignored by new-style webhooks)

  • verbose (bool) – How much detail to display.

  • die (bool) – If false, prints warnings. If true, raises exceptions.

Example:

sc.slacknotification('Long process is finished')
sc.slacknotification(webhook='/.slackurl', channel='@username', message='Hi, how are you going?')

What’s the point? Add this to the end of a very long-running script to notify your loved ones that the script has finished.

Version: 2018sep25