ipyslack 1.2.1

Creator: bradpython12

Last updated:

Add to Cart

Description:

ipyslack 1.2.1

Installation
$ pip install ipyslack


Usage

Load the extension:
%load_ext ipyslack

Configure Slack API:
%slack_setup -t <api_token> -c <target_channel>
To obtain the API token visit this page.
The <target_channel> parameter may either denote a channel (e.g. #general) or a user (e.g. @me).
Adding the option -u true to %slack_setup will make yourself the sender of all messages. Otherwise (default) the messages originate from slackbot.
In order to avoid having to write the API token in every notebook, you can create a file containing the same configuration line:
-t <api_token> -c <target_channel> -u false
You can then load this configuration in the notebook by invoking:
%slack_setup <filename>
Even simpler, if you don’t call %slack_setup at all, the extension will try to auto-configure itself on first use
by searching for the files ~/.ipyslack.cfg and .ipyslack.cfg (in this order) and
trying to load configuration from these.
Later files in this search order override the settings of the previous ones. That is, you can specify -t <api_token> -c #default_group
in the global ~/.ipyslack.cfg, and only override -c #project_group in the local .ipyslack.cfg.

Now adding:
%%slack_notify <message>
at the top of any cell will send <message> to <target_channel> whenever cell execution is completed.
The patterns {out} and {err} within <message> will be substituted with stdout or stderr from the cell’s execution. The pattern {exc} denotes the exception (if any was thrown). The string \n denotes a new line. Simiarly, any variable named x in your workspace can be referred to as {x} (in fact, you can use the standard format string notation).
Example:
%%slack_notify *Completed {len(results)} trials. Last result: {results[-1]}!* :heavy_plus_sign:\nStdout: {out}\nStderr: {err}\nException: {exc}

In addition, the line-magic %slack_send <message> lets you send notifications about partial results. E.g.:
%%slack_notify Completed. Final accuracy: {accuracy}. {exc}
... computation ...
%slack_send Half-way! Current accuracy: {accuracy}
... computation ...




See also

IPyTelegram: https://github.com/kalaidin/ipytelegram/

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.