diff --git a/slackmail.py b/slackmail.py index fc20339..2fda135 100644 --- a/slackmail.py +++ b/slackmail.py @@ -1,5 +1,8 @@ #!/usr/bin/python # Copyright 2015 (c) Anna Schumaker. + +import json +import sys from urllib import request @@ -17,13 +20,20 @@ def call_method(method, args = dict()): server = "https://slack.com/api/" with request.urlopen("%s/%s?%s" % (server, method, argstr)) as f: - print(f.read().decode()) + return json.loads(f.read().decode()) + return {"ok" : False} def call_method_auth(method, args = dict()): - args['token'] = TOKEN - call_method(method, args) + args["token"] = TOKEN + return call_method(method, args) -call_method("api.test") -call_method_auth("auth.test") + +# +# Test connection before doing anything else +# +if call_method("api.test")["ok"] == False: + sys.exit(1) +if call_method_auth("auth.test")["ok"] == False: + sys.exit(1)