From 254123f6403c00222349a17e50a67e848cdcc1c5 Mon Sep 17 00:00:00 2001 From: evilbeast Date: Mon, 5 Sep 2022 16:39:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=85=AC?= =?UTF-8?q?=E4=BC=97=E5=8F=B7=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- examples/get_publics.py | 35 +++++++++++++++++++++++++++++++++++ ntchat/conf/__init__.py | 2 +- ntchat/const/send_type.py | 3 +++ ntchat/core/wechat.py | 6 ++++++ setup.py | 2 +- 6 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 examples/get_publics.py diff --git a/README.md b/README.md index 200290c..9a55e21 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

NtChat

- release + release License

diff --git a/examples/get_publics.py b/examples/get_publics.py new file mode 100644 index 0000000..1a99452 --- /dev/null +++ b/examples/get_publics.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +import sys +import time +import ntchat + + +def version_tuple(v): + return tuple(map(int, (v.split(".")))) + + +if version_tuple(ntchat.__version__) < version_tuple('0.1.8'): + print("error: ntchat version required 0.1.8, use `pip install -U ntchat` to upgrade") + sys.exit() + +wechat = ntchat.WeChat() + +# 打开pc微信, smart: 是否管理已经登录的微信 +wechat.open(smart=True) + +# 等待登录 +wechat.wait_login() + +# 获取群列表并输出 +rooms = wechat.get_publics() + +print("公众号列表: ") +print(rooms) + +# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 +try: + while True: + time.sleep(0.5) +except KeyboardInterrupt: + ntchat.exit_() + sys.exit() diff --git a/ntchat/conf/__init__.py b/ntchat/conf/__init__.py index 685af60..09496f8 100644 --- a/ntchat/conf/__init__.py +++ b/ntchat/conf/__init__.py @@ -1,4 +1,4 @@ -VERSION = '0.1.7' +VERSION = '0.1.8' LOG_LEVEL = "DEBUG" LOG_KEY = 'NTCHAT_LOG' diff --git a/ntchat/const/send_type.py b/ntchat/const/send_type.py index 05b8c5a..f5cada4 100644 --- a/ntchat/const/send_type.py +++ b/ntchat/const/send_type.py @@ -7,6 +7,9 @@ MT_GET_CONTACTS_MSG = 11030 # 获取所有的群 MT_GET_ROOMS_MSG = 11031 +# 获取公众号列表 +MT_GET_PUBLICS_MSG = 11033 + # 获取指定的群成员 MT_GET_ROOM_MEMBERS_MSG = 11032 diff --git a/ntchat/core/wechat.py b/ntchat/core/wechat.py index ec0cdee..722514b 100644 --- a/ntchat/core/wechat.py +++ b/ntchat/core/wechat.py @@ -181,6 +181,12 @@ class WeChat: """ return self.__send_sync(send_type.MT_GET_CONTACTS_MSG) + def get_publics(self): + """ + 获取关注公众号列表 + """ + return self.__send_sync(send_type.MT_GET_PUBLICS_MSG) + def get_contact_detail(self, wxid): """ 获取联系人详细信息 diff --git a/setup.py b/setup.py index 872cdfd..85cb245 100644 --- a/setup.py +++ b/setup.py @@ -194,7 +194,7 @@ extension.extra_compile_cpp_args = extra_compile_cpp_args[target_os] setup( name='ntchat', - version='0.1.7', + version='0.1.8', description='About Conversational RPA SDK for Chatbot Makers', long_description="", long_description_content_type='text/markdown',