begin an api

This commit is contained in:
saces 2026-03-16 10:22:25 +01:00
parent 442aaf0056
commit 1bfae104fc
3 changed files with 121 additions and 17 deletions

View file

@ -1,9 +1,7 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import json
import click
from _pygomx import ffi, lib
from pygomx import CliV0
@click.command()
@ -13,18 +11,8 @@ def whoami(hs_url, token):
"""this token belongs to?"""
if hs_url is None and token is None:
r = lib.cliv0_mxpassitem(b".mxpass", b"*", b"*", b"*")
cli = CliV0.from_mxpass(".mxpass", "*", "*", "*")
else:
cli = CliV0(hs_url, token)
result = ffi.string(r).decode("utf-8")
lib.FreeCString(r)
result_dict = json.loads(result)
hs_url = result_dict["Matrixhost"]
token = result_dict["Token"]
r = lib.cliv0_whoami(
hs_url.encode(encoding="utf-8"), token.encode(encoding="utf-8")
)
result = ffi.string(r)
lib.FreeCString(r)
print(result.decode("utf-8"))
print(cli.Whoami())