Decode reply from slack into a python dictionary structure
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
13050a1486
commit
883504da38
20
slackmail.py
20
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)
|
||||
|
|
Loading…
Reference in New Issue