Xml文件保存聊天记录
版权所有,转载请注明出处:http://guangboo.org/2013/01/29/save-chat-history-with-xml
利用上篇文章定义的存储聊天记录的接口,这里具体实现使用xml文件保存聊天记录的功能。
代码如下:
if __name__ == '__main__': sql = XmlStorageHistory('zhang@gmail.com','wang2xiao@gmail.com', 'c:\\his2')
sql.open() sql.write('wang2xiao@gmail.com', 'Wang, 2Xiao', 'msg', 'Hi, What are you doing?',datetime.datetime.now()) sql.write('zhang@gmail.com', 'Zhang, Guangbo', 'msg', 'Hi, Nothing.', datetime.datetime.now()) for row in sql.read(): print row sql.close()
测试结果:
('wang2xiao@gmail.com', 'Wang, 2Xiao', 'msg', None, '2013-01-29 23:10:49.937000')('zhang@gmail.com', 'Zhang, Guangbo', 'msg', None, '2013-01-29 23:10:49.937000')