diff --git a/.gitignore b/.gitignore index 94bc20a..e22a353 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ token +*.pyc *.sw* diff --git a/slack/__init__.py b/slack/__init__.py new file mode 100644 index 0000000..03f7ae3 --- /dev/null +++ b/slack/__init__.py @@ -0,0 +1,5 @@ +# +# Copyright 2015 (c) Anna Schumaker +# + +from . import api diff --git a/slack/api.py b/slack/api.py new file mode 100644 index 0000000..d99be24 --- /dev/null +++ b/slack/api.py @@ -0,0 +1,17 @@ +# +# Copyright 2015 (c) Anna Schumaker +# +import json +from urllib import request + +__SLACK_SERVER = "https://slack.com/api" + +def call(method, **kwargs): + args = "&&".join("%s=%s" % x for x in kwargs.items()) + with request.urlopen("%s/%s?%s" % (__SLACK_SERVER, method, args)) as req: + return json.loads(req.read().decode()) + return {"ok" : False} + + +def test(): + return call("api.test")["ok"] diff --git a/slackmail.py b/slackmail.py index 3bb4244..40d4e85 100644 --- a/slackmail.py +++ b/slackmail.py @@ -1,6 +1,7 @@ #!/usr/bin/python # Copyright 2015 (c) Anna Schumaker. +import slack import json import os import sys @@ -35,7 +36,8 @@ def call_method_auth(method, args = dict()): # # Test connection before doing anything else # -if call_method("api.test")["ok"] == False: +if slack.api.test() == False: + print("Connection error!") sys.exit(1) auth = call_method_auth("auth.test") if auth["ok"] == False: