Decode reply from slack into a python dictionary structure

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-05-26 09:44:17 -04:00
parent 13050a1486
commit 883504da38
1 changed files with 15 additions and 5 deletions

View File

@ -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)