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 enviarMensaje(self, request, context):
        cur = cnx.cursor()
        sender = request.sender
        receiver = request.receiver
        contenido = request.content
        date = datetime.datetime.now()
        query = "INSERT INTO photogram.mensaje (sender, receiver, content, date) values (%s,%s,%s,%s)"
        values = (sender, receiver, contenido, date)
        cur.execute(query, values)
        cnx.commit()
        #insertarlo en la bd

        self.messages.clear()
        cur.execute("SELECT * FROM photogram.mensaje")
        for msj in cur.fetchall():
            print(msj)
            self.messages.append(msj)
        return structure.Empty(response="success")