-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegen.py
More file actions
executable file
·36 lines (29 loc) · 893 Bytes
/
codegen.py
File metadata and controls
executable file
·36 lines (29 loc) · 893 Bytes
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
#!/usr/bin/python3
"""Code generation for AsyncClient"""
import json
# default values for some URIs and arguments
DEFAULTS = {
"sendChat": {"all": True},
"updateChat": {"id_from": 0},
"updateLog": {"id_from": 0},
}
with open("webgui_uris.json", "rt") as fh:
uris: dict = json.load(fh)
for uri, reqresp in uris.items():
req = reqresp["examples"][0]["request"]
resp = reqresp["examples"][0]["response"]
del req["uri"]
fargs = ""
dargs = ""
for argname, argval in req.items():
fargs += f", {argname}: {type(argval).__name__}"
try:
fargs += f" = {DEFAULTS[uri][argname]!r}"
except KeyError:
pass
dargs += f', "{argname}": {argname}'
print(
f" @uri:\n"
f" async def {uri}(self{fargs}):\n"
f' return await self.request({{"uri": "{uri}"{dargs}}})\n'
)