mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 03:22:29 +00:00
Support converting .tl -> .json
This commit is contained in:
31
setup.py
31
setup.py
@@ -61,13 +61,13 @@ def generate(which):
|
||||
generate_errors, generate_tlobjects, generate_docs, clean_tlobjects
|
||||
|
||||
with open(INVALID_BM_IN) as f:
|
||||
ib = set(json.load(f))
|
||||
invalid_bot_methods = set(json.load(f))
|
||||
|
||||
layer = find_layer(TLOBJECT_IN_TL)
|
||||
errors = list(parse_errors(ERRORS_IN_JSON, ERRORS_IN_DESC))
|
||||
tlobjects = list(itertools.chain(
|
||||
parse_tl(TLOBJECT_IN_CORE_TL, layer=layer, invalid_bot_methods=ib),
|
||||
parse_tl(TLOBJECT_IN_TL, layer=layer, invalid_bot_methods=ib)))
|
||||
parse_tl(TLOBJECT_IN_CORE_TL, layer, invalid_bot_methods),
|
||||
parse_tl(TLOBJECT_IN_TL, layer, invalid_bot_methods)))
|
||||
|
||||
if not which:
|
||||
which.extend(('tl', 'errors'))
|
||||
@@ -110,6 +110,31 @@ def generate(which):
|
||||
else:
|
||||
generate_docs(tlobjects, errors, layer, DOCS_IN_RES, DOCS_OUT)
|
||||
|
||||
if 'json' in which:
|
||||
which.remove('json')
|
||||
print(action, 'JSON schema...')
|
||||
mtproto = 'mtproto_api.json'
|
||||
telegram = 'telegram_api.json'
|
||||
if clean:
|
||||
for x in (mtproto, telegram):
|
||||
if os.path.isfile(x):
|
||||
os.remove(x)
|
||||
else:
|
||||
def gen_json(fin, fout):
|
||||
methods = []
|
||||
constructors = []
|
||||
for tl in parse_tl(fin, layer):
|
||||
if tl.is_function:
|
||||
methods.append(tl.to_dict())
|
||||
else:
|
||||
constructors.append(tl.to_dict())
|
||||
what = {'constructors': constructors, 'methods': methods}
|
||||
with open(fout, 'w') as f:
|
||||
json.dump(what, f, indent=2)
|
||||
|
||||
gen_json(TLOBJECT_IN_CORE_TL, mtproto)
|
||||
gen_json(TLOBJECT_IN_TL, telegram)
|
||||
|
||||
if which:
|
||||
print('The following items were not understood:', which)
|
||||
print(' Consider using only "tl", "errors" and/or "docs".')
|
||||
|
Reference in New Issue
Block a user