def read_message(self, msg_list): count = 0 c = self.__conn.cursor() c.execute( "SELECT id,from_user,from_nick,from_remark,to_user,to_nick,content,recvtime,reply,sendtime,status FROM message WHERE status=0 ORDER BY id LIMIT 5" ) rows = c.fetchall() if not rows: return count for row in rows: msg = Message() msg.id = row[0] msg.from_user = row[1] msg.from_nick = row[2] msg.from_remark = row[3] msg.to_user = row[4] msg.to_nick = row[5] msg.content = row[6] msg.recvtime = row[7] msg.reply = row[8] msg.sendtime = row[9] msg.status = row[10] msg_list.append(msg) count = count + 1 print("read message id " + str(msg.id)) if count > 10: break return count
def text_reply(msg): ''' print "MsgType: " + str(msg.MsgType) print "MsgId: " + str(msg.MsgId) print "FromUserName: "******"ToUserName: "******"Content: " + msg.Content print "Message: " + msg.text print "Actual Nick Name: " + msg.actualNickName print "IsAt: " + str(msg.isAt) ''' # if msg.isAt: print "New Message: " + msg.text m = Message() m.id = 0 m.from_user = msg.FromUserName m.from_nick = msg.actualNickName m.from_remark = ChatDB.get_remark_by_userid(m.from_user) m.to_user = msg.ToUserName m.to_nick = ChatDB.get_nickname_by_userid(m.to_user) m.content = msg.Content m.recvtime = get_cur_time() m.status = 0 ChatDB.save_new_message(m) # msg.user.send(u'@%s\u2005I received: %s' % (msg.actualNickName, msg.text)) pass
def test_insert_message(): for i in range(1, 2): msg = Message() msg.id = 0 msg.from_user = "******" msg.from_nick = "常胜将军" msg.to_user = "******" msg.to_nick = "李四" msg.content = "1,大,200" # msg.content = "取消" msg.recvtime = get_cur_time() msg.status = 0 last_id = ChatDB.save_new_message(msg) print("Message ID inserted is " + str(last_id)) msg.id = last_id msg.reply = "success" msg.sendtime = get_cur_time() msg.status = 2 # ChatDB.update_reply_message(msg) pass