-
Notifications
You must be signed in to change notification settings - Fork 0
/
sn_clients.py
52 lines (42 loc) · 976 Bytes
/
sn_clients.py
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
45
46
47
48
49
50
51
52
import json
import requests
import os
SN_REST_BASE_URL = "https://www.scoutnet.de/api/0.2/"
SN_RPC_URL = "https://www.scoutnet.de/jsonrpc/server.php"
def sn_rest(path, *args):
if args:
params = {
"json": json.dumps(args)
}
else:
params = {}
return requests.get(
SN_REST_BASE_URL + path,
params=params
).json()
class RPCError(Exception):
pass
def rpc(url, method, *params):
"""
JSON-RPC 1.0 über HTTP(S) POST
"""
call_id = os.urandom(16).hex()
json_data = {
"method": method,
"params": params,
"id": call_id
}
got = requests.post(
url,
json=json_data
).json()
e = got["error"]
if e is not None:
raise RPCError(e)
return got["result"]
def sn_rpc_get(*params):
return rpc(
SN_RPC_URL,
"get_data_by_global_id",
*params
)