Skip to content

Instantly share code, notes, and snippets.

@b1naryth1ef
Created February 20, 2013 22:03
Show Gist options
  • Save b1naryth1ef/5000062 to your computer and use it in GitHub Desktop.
Save b1naryth1ef/5000062 to your computer and use it in GitHub Desktop.
Bukkit JSONAPI Python API (That doesnt suck, and uses requests)
import requests, hashlib, json
class API(object):
def __init__(self, host, port, user, pw, salt="mysalt"):
self.host = host
self.port = port
self.user = user
self.pw = pw
self.salt = salt
self.url = "http://%s:%s/api/call" % (self.host, self.port)
def call(self, method, *args):
auth = hashlib.sha256("%s%s%s%s" % (self.user, method, self.pw, self.salt)).hexdigest()
kwargs = {
"method": method,
"key": auth,
"args": json.dumps(args)
}
print requests.get(self.url, params=kwargs).json
#x = API("localhost", 20059, "user", "password")
#x.call("system.getServerClockDebug")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment