diff --git a/examples/auto_accept_friend_request.py b/examples/auto_accept_friend_request.py index 1695f39..6af0f36 100644 --- a/examples/auto_accept_friend_request.py +++ b/examples/auto_accept_friend_request.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys +import time import ntchat import xml.dom.minidom @@ -24,9 +25,11 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message): wechat_instance.accept_friend_request(encryptusername, ticket, int(scene)) +# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 try: while True: - pass + time.sleep(0.5) except KeyboardInterrupt: ntchat.exit_() sys.exit() + diff --git a/examples/echo_bot_msg_register.py b/examples/echo_bot_msg_register.py index 41de497..6bd29ec 100644 --- a/examples/echo_bot_msg_register.py +++ b/examples/echo_bot_msg_register.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys +import time import ntchat wechat = ntchat.WeChat() @@ -22,9 +23,10 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message): wechat_instance.send_text(to_wxid=from_wxid, content=f"你发送的消息是: {data['msg']}") +# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 try: while True: - pass + time.sleep(0.5) except KeyboardInterrupt: ntchat.exit_() sys.exit() diff --git a/examples/echo_bot_on.py b/examples/echo_bot_on.py index 34be141..32ccf54 100644 --- a/examples/echo_bot_on.py +++ b/examples/echo_bot_on.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys +import time import ntchat wechat = ntchat.WeChat() @@ -22,9 +23,10 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message): # 监听接收文本消息 wechat.on(ntchat.MT_RECV_TEXT_MSG, on_recv_text_msg) +# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 try: while True: - pass + time.sleep(0.5) except KeyboardInterrupt: ntchat.exit_() sys.exit() diff --git a/examples/get_contacts.py b/examples/get_contacts.py index 372ee30..7a6e1c1 100644 --- a/examples/get_contacts.py +++ b/examples/get_contacts.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys +import time import ntchat wechat = ntchat.WeChat() @@ -17,9 +18,11 @@ print("联系人列表: ") print(contacts) +# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 try: while True: - pass + time.sleep(0.5) except KeyboardInterrupt: ntchat.exit_() sys.exit() + diff --git a/examples/get_rooms.py b/examples/get_rooms.py index 644f93d..f187f7c 100644 --- a/examples/get_rooms.py +++ b/examples/get_rooms.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys +import time import ntchat wechat = ntchat.WeChat() @@ -17,9 +18,11 @@ print("群列表: ") print(rooms) +# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 try: while True: - pass + time.sleep(0.5) except KeyboardInterrupt: ntchat.exit_() sys.exit() + diff --git a/examples/send_text.py b/examples/send_text.py index 0f217dc..536aa3c 100644 --- a/examples/send_text.py +++ b/examples/send_text.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys +import time import ntchat wechat = ntchat.WeChat() @@ -13,12 +14,14 @@ wechat.wait_login() # 向文件助手发送一条消息 wechat.send_text(to_wxid="filehelper", content="hello, filehelper") +# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 try: while True: - pass + time.sleep(0.5) except KeyboardInterrupt: ntchat.exit_() sys.exit() +