Python编写MSN机器人


打算编写一个MSN机器人以便支持我的字典查询网站。

看了msnp的类,似乎能够满足我的基本需求。这些是一个简单的示例。

其代码如下:

  1. import msnp
  2. import time
  3. class MsnChatListener(msnp.ChatCallbacks):
  4.     def message_received(self, passport_id, display_name, text, charset):
  5.         print '%s: %s' % (passport_id, text)
  6.         self.chat.send_message(text, charset)
  7.  
  8. class MsnListener(msnp.SessionCallbacks):
  9.     def chat_started(self, chat):
  10.         callbacks=MsnChatListener()
  11.         chat.callbacks = callbacks
  12.         callbacks.chat = chat
  13.  
  14.     def state_changed(self, state):
  15.         if state == msnp.States.ONLINE:
  16.             print 'You are now online.'
  17.  
  18. msn = msnp.Session(MsnListener())
  19.  
  20. msn.login('emylekao@163.com', 'yg6xx,y6mmx11!')
  21. msn.sync_friend_list()
  22.  
  23. while True:
  24.     msn.process(chats = True)
  25.     time.sleep(1)

参考资料:msnp tutorial


感谢您的关注。您现在可以 留言(0)留下通告地址



Leave a Reply

Note: Any comments are permitted only because the site owner is letting you post, and any comments will be removed for any reason at the absolute discretion of the site owner.

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image