import sys
import grpc
import compose_pb2
import compose_pb2_grpc

def run():
    # get the address to run on
    port = sys.argv[1]
    # create and insecure channel
    with grpc.insecure_channel(port) as channel:
        stub = compose_pb2_grpc.ComposeStub(channel)
        while True:
            # read from the keyboard
            values = input().split(',')
            # a search request is made
            if values[0] == 'C':
                response = stub.Search(compose_pb2.ConsultPayload(id=int(values[1])))
                print(response.name, response.matricula, response.course, response.credits)
            # terminate communication request is made
            elif values[0] == 'T':
                response = stub.Terminate(compose_pb2.EndPayload())
                print(response.response)
                break
            # other inputs which doens't start wiht C ou T are ingnored
            else:
                continue

if __name__ == '__main__':
    run()