Example #1
0
 def Messages(self, id, context):
     r = Chat_pb2.MessageList()
     try:
         f = open("log/log.txt", "r")
         for i in f:
             l = i.split("@")
             if (int(l[1][1:-1].split("#")[1]) == id.id):
                 men = l[5][1:-1].split(";")
                 r.msn.append(
                     Chat_pb2.Message(id=int(men[0]),
                                      contenido=men[1],
                                      timestamp=men[2]))
         f.close()
     except:
         r.msn.append(Chat_pb2.Empty())
     return r
Example #2
0
 def SendMessage(self, contenido, destino):
     try:
         response = self.stub.SendMessage(
             Chat_pb2.Message(
                 emisor=self.my_user,
                 contenido=contenido,
                 timestamp=time.strftime("%c"),
                 receptor=Chat_pb2.User(id=int(destino.split('#')[1]),
                                        nombre=destino.split('#')[0]),
                 id=self.stub.New_message(Chat_pb2.Id(id=self.id)).id))
         if not response.flag:
             print(
                 "NO existe el usuario a quien se le quiere enviar el mensaje "
             )
     except grpc.RpcError as err:
         print(err)