Created
November 1, 2018 09:48
-
-
Save thomaspinder/e99958796e58a4de92449c0bf46e861c to your computer and use it in GitHub Desktop.
Slack notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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