niming_backend/utils/ighelper.py

44 lines
1.3 KiB
Python
Raw Normal View History

2024-12-18 03:07:56 +08:00
from typing import Tuple
import os
import grpc
from protobuf_files import igapi_pb2_grpc
from protobuf_files.igapi_pb2 import Request, Reply
2024-12-18 13:00:33 +08:00
IGRPC_HOST = os.getenv("IGRPC_HOST", None)
2024-12-18 03:07:56 +08:00
def request_account_info() -> Tuple[dict, int]:
2024-12-18 13:00:33 +08:00
with grpc.insecure_channel(IGRPC_HOST) as channel:
2024-12-18 03:07:56 +08:00
stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.account_info(Request())
return dict(res.result.items()), res.err
def request_login() -> Tuple[dict, int]:
2024-12-18 13:00:33 +08:00
with grpc.insecure_channel(IGRPC_HOST) as channel:
2024-12-18 03:07:56 +08:00
stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.login(Request())
return dict(res.result.items()), res.err
def request_queue() -> dict:
2024-12-18 13:00:33 +08:00
with grpc.insecure_channel(IGRPC_HOST) as channel:
2024-12-18 03:07:56 +08:00
stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.queue(Request())
return dict(res.result.items())
def request_upload(aid:int) -> Tuple[dict, int]:
2024-12-18 13:00:33 +08:00
with grpc.insecure_channel(IGRPC_HOST) as channel:
2024-12-18 03:07:56 +08:00
stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.upload(Request(code=aid))
return dict(res.result.items()), res.err
def request_delete(aid:int, code:str) -> Tuple[dict, int]:
2024-12-18 13:00:33 +08:00
with grpc.insecure_channel(IGRPC_HOST) as channel:
2024-12-18 03:07:56 +08:00
stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.delete(Request(code=aid, args=[code]))
return dict(res.result.items()), res.err