tiny Nxt API import urllib2 import requests import json bURL http 127

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
tiny Nxt API
"""
import urllib2
import requests
import json
bURL = "http://127.0.0.1:7876/nxt?"
def build_req(requestType, **kwargs):
url = bURL +"requestType="+requestType
for k,v in kwargs.items():
url +="&"+k+"="+v
return url
def make_req(url):
r = requests.get(url)
j = json.loads(r.content)
return j
def get_Account(accountID):
"""
{"unconfirmedBalanceNQT":"4858100000000","guaranteedBalanceNQT":"4858000000000",
"effectiveBalanceNXT":48580,"accountRS":"NXT-PGF9-SHUV-NLB2-8SJK3","forgedBalanceNQT":"0",
"balanceNQT":"4858100000000","publicKey":"05f633d1dd3a55291d691c76fe0e43d496094f1033c609b6d9ba864b80bcf959",
"requestProcessingTime":57,"account":"6973288302950136231"}
"""
url = build_req("getAccount",account=accountID)
j = make_req(url)
return j
def get_alias(aliasID):
url = build_req("getAlias",aliasName=aliasID)
j = make_req(url)
return j
#aliasName=ALIAS_NAME
r = get_Account("6973288302950136231")
print r["publicKey"]
print get_alias("alice")["aliasURI"]