Skip to content

Instantly share code, notes, and snippets.

@thomaspinder
Created November 1, 2018 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaspinder/e99958796e58a4de92449c0bf46e861c to your computer and use it in GitHub Desktop.
Save thomaspinder/e99958796e58a4de92449c0bf46e861c to your computer and use it in GitHub Desktop.
Slack notifier
"""
If you place this script at the bottom of your Python work, then it'll send you a notification on Slack once your code has finished running. Potentially useful if your code takes several hours to run as it saves having to check on its progress.
To run, you'll need to install the following two libraries:
slackclient==1.2.1
slacker==0.9.65
And then sign up for a Slack API key. Once these two steps have been done you can run the following code, replacing the name and key values with your own.
"""
from slacker import Slacker
from slackclient import SlackClient
token = 'INSERT_TOKEN_HERE'
full_name = 'FIRST_NAME SECOND_NAME'
# Connect
slack = Slacker(token)
response = slack.users.list()
users = response.body['members']
id = [user['id'] for user in users if full_name in user['real_name']]
print('User ID: {}'.format(id[0]))
def done_message(token, id):
# Post message
connection = SlackClient(token)
connection.api_call('chat.postMessage', channel=my_id, text='<@{}>, Script Complete'.format(id),
as_user=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment