slackmail/slackmail.py

30 lines
678 B
Python
Raw Normal View History

#!/usr/bin/python
# Copyright 2015 (c) Anna Schumaker.
from urllib import request
# TODO: Move the token file outside of code directory
TOKEN = ""
with open("token") as f:
TOKEN = f.read().strip()
def call_method(method, args = dict()):
arglist = []
for (key, value) in args.items():
arglist += ["%s=%s" % (key, value)]
argstr = "&&".join(arglist)
server = "https://slack.com/api/"
with request.urlopen("%s/%s?%s" % (server, method, argstr)) as f:
print(f.read().decode())
def call_method_auth(method, args = dict()):
args['token'] = TOKEN
call_method(method, args)
call_method("api.test")
call_method_auth("auth.test")