diff --git a/slack/__init__.py b/slack/__init__.py index 03f7ae3..7bbb0a0 100644 --- a/slack/__init__.py +++ b/slack/__init__.py @@ -3,3 +3,20 @@ # from . import api +from . import auth +import sys + + + +# +# Verify connection and setup team information. +# + +if api.test() == False: + print("Connection error, cannot continue.") + sys.exit(1) + +__auth = auth.test() +if __auth == None: + sys.exit(1) +__TEAM = __auth["team"] diff --git a/slack/auth.py b/slack/auth.py new file mode 100644 index 0000000..611c13d --- /dev/null +++ b/slack/auth.py @@ -0,0 +1,16 @@ +# +# Copyright 2015 (c) Anna Schumaker +# +from . import api + +# TODO: Move the token config file outside of code directory +__TOKEN = "" +with open("token") as f: + __TOKEN = f.read().strip() + +def test(): + ret = api.call("auth.test", token = __TOKEN) + if ret["ok"] == False: + print("Authentication error: %s." % ret["error"]) + return None + return ret diff --git a/slackmail.py b/slackmail.py index 40d4e85..0584fbf 100644 --- a/slackmail.py +++ b/slackmail.py @@ -4,6 +4,7 @@ import slack import json import os +import slack import sys from datetime import datetime from urllib import request @@ -33,16 +34,6 @@ def call_method_auth(method, args = dict()): -# -# Test connection before doing anything else -# -if slack.api.test() == False: - print("Connection error!") - sys.exit(1) -auth = call_method_auth("auth.test") -if auth["ok"] == False: - sys.exit(1) -team = auth["team"]