Jupyter + Slack Driven Development

This example shows how environment variables allow the python core to publish a message into Slack to notify the associated user with a message containing the line number and source code that threw the exception.


In [ ]:
import os, sys, json

sys.path.insert(0, os.getenv('ENV_PYTHON_SRC_DIR', '/opt/work/src'))

from pycore import PyCore

print 'Initializing Python Core'
core = PyCore()

print 'These Slack Env variables are set by docker'
slackbotname   = str(os.getenv('ENV_SLACK_BOTNAME'))
slackchannel   = str(os.getenv('ENV_SLACK_CHANNEL'))
slacknotifyuser= str(os.getenv('ENV_SLACK_NOTIFY_USER'))
slacktoken     = str(os.getenv('ENV_SLACK_TOKEN'))
slackenvname   = str(os.getenv('ENV_SLACK_ENVNAME'))

core.lg('Slack Env - Bot(' + slackbotname + ') Channel(' + slackchannel + ') NotifyThisUser(' + slacknotifyuser + ') Token(' + slacktoken + ') Env(' + slackenvname + ')', 1)
try:
    core.lg('')
    core.lg('-----------------------------------------------------------------------------', 2)
    core.lg('This will throw an exception and should post a message into the Slack Channel')
    core.lg('')
    THIS_VARIABLE_DOES_NOT_EXIST
except Exception,e:
    core.handle_send_slack_internal_ex(e)
# end of try/ex