ntchat/examples/search_contacts.py
2022-09-04 20:40:45 +08:00

47 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- 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.7'):
print("error: ntchat version required 0.1.7, use `pip install -U ntchat` to upgrade")
sys.exit()
wechat = ntchat.WeChat()
# 打开pc微信, smart: 是否管理已经登录的微信
wechat.open(smart=True)
# 等待登录
wechat.wait_login()
# 根据wxid模糊查询查询联系人
contacts = wechat.search_contacts(wxid="wxid_")
print(contacts)
# 根据微信号模糊查询联系人
# contacts = wechat.search_contacts(account="")
# 根据昵称模糊查询联系人, 如昵称包含`小`的联系人
contacts = wechat.search_contacts(nickname="")
print(contacts)
# 根据备注查询联系人
contacts = wechat.search_contacts(remark="备注")
print(contacts)
# 以下是为了让程序不结束如果有用于PyQt等有主循环消息的框架可以去除下面代码
try:
while True:
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()