本文整理汇总了Python中itchat.search_friends方法的典型用法代码示例。如果您正苦于以下问题:Python itchat.search_friends方法的具体用法?Python itchat.search_friends怎么用?Python itchat.search_friends使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类itchat
的用法示例。
在下文中一共展示了itchat.search_friends方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_to_person
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def send_to_person(username, file_names):
"""
发送给某个人
:param username: 发送对象的昵称
:param filename: 文件名
:return:
"""
room = itchat.search_friends(name=r'%s' % username)
userName = room[0]['UserName']
try:
if isinstance(file_names, list):
# 多个图片
for file_name in file_names:
itchat.send_image(file_name, toUserName=userName)
else:
# 一个图片
itchat.send_image(file_names, toUserName=userName)
print('发送完毕!')
except:
print('发送出错!')
示例2: send_word_to_person
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def send_word_to_person(name, content):
"""
发送消息给某个人
:param name:
:param content:
:return:
"""
users = itchat.search_friends(name)
userName = users[0]['UserName']
itchat.send(content, toUserName=userName)
示例3: send_file_to_person
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def send_file_to_person(name, filename):
"""
发送文件给某个人
:param name:
:param filename:
:return:
"""
users = itchat.search_friends(name)
userName = users[0]['UserName']
itchat.send_file(filename, toUserName=userName)
示例4: is_online
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def is_online():
"""
判断微信是否在线
:return: Bool
"""
try:
if itchat.search_friends():
return True
except IndexError:
return False
return True
示例5: SendFriend
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def SendFriend(self):
global frind_dict
for i in range(len(frind_dict)):
if(self.d_Listname.selection_includes(i) == True):
key = self.d_Listname.get(i)
value = frind_dict[key]
str = self.d_input.get(1.0, END)
self.d_input.delete(1.0, END)
frind = itchat.search_friends(nickName=value)[0]['UserName']
itchat.send(str,toUserName=frind)
示例6: SendText2Friend
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def SendText2Friend(msg,nick_name='filehelper'): #已经测试成功,可用
'''
@ 发送文本消息给指定好友,如果不指定nick_name则发送给自己的文件助手
'''
if nick_name == 'filehelper':
itchat.send(msg,toUserName = 'filehelper')
else:
users = itchat.search_friends(name=nick_name)
# print(users)
who = users[0]['UserName']
# print(who)
itchat.send(msg,toUserName = who)
示例7: get_city_by_uuid
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def get_city_by_uuid(uid):
"""
通过用户的uid得到用户的城市
最好是与机器人是好友关系
"""
itchat.get_friends(update=True)
info = itchat.search_friends(userName=uid)
# print('info:'+str(info))
if not info:
return None
city = info.city
# print('city:'+city)
return city
示例8: get_friend
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def get_friend(wechat_name, update=False):
"""
根据用户名获取用户数据
:param wechat_name: str 用户名
:param update: bool 强制更新用户数据
:return: obj 单个好友信息
"""
if update: itchat.get_friends(update=True)
if not wechat_name: return None
friends = itchat.search_friends(name=wechat_name)
if not friends: return None
return friends[0]
示例9: add_friend
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def add_friend(msg):
itchat.add_friend(**msg['Text']) # 该操作会自动将新好友的消息录入,不需要重载通讯录
user_info = itchat.search_friends(userName=msg['RecommendInfo']['UserName'])
itchat.send_msg(u'Hi,我是一个智能机器人,能帮助您自动化的管理微信群,把我拉入群,我就可以开始为你工作啦', user_info['UserName'])
upsert_user(user_info)
示例10: text_reply
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def text_reply(msg):
print msg
# 微信里,每个用户和群聊,都使用很长的ID来区分
if msg["MsgType"] == 49:
print "个人分享文章地址链接Url:" + "---------------------------"
xmlcontent = lxml.etree.HTML(get_html(msg["Url"]))
print xmlcontent
title = xmlcontent.xpath('//h2[@class="rich_media_title"]/text()')
imgArray = xmlcontent.xpath('//img[@data-type="png"]/@data-src')
# 下载图片
source = xmlcontent.xpath('//span[@class="rich_media_meta rich_media_meta_text rich_media_meta_nickname"]/text()')
time = xmlcontent.xpath('//em[@class="rich_media_meta rich_media_meta_text"]/text()')
print "来源"
print source, time
# 下载图片
print "下载图片"
# print imgArray
# print title[0]
get_image(title, imgArray, source, time,msg["Url"])
print msg["Url"]
print "个人分享文章类型编号MsgType:" + "---------------------------"
print msg["MsgType"]
print "个人分享Content:" + "---------------------------"
print msg["Content"]
print "个人分享FromUserName:" + "---------------------------"
print msg["FromUserName"]
print "个人分享ToUserName:" + "---------------------------"
print msg["ToUserName"]
print "个人分享链接标题FileName:" + "---------------------------"
print msg["FileName"]
print "------------个人"
# 获取到的信息是某某人和登录者之间的通讯,如果不是和登录这通讯就获取不到
print itchat.search_friends(userName=msg['FromUserName'])['NickName']
print itchat.search_friends(userName=msg['ToUserName'])['NickName']
else:
print "不是个人分享的文章"
# 处理群聊消息
示例11: is_online
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import search_friends [as 别名]
def is_online(auto_login=False):
"""
判断是否还在线。
:param auto_login: bool,当为 Ture 则自动重连(默认为 False)。
:return: bool,当返回为 True 时,在线;False 已断开连接。
"""
def _online():
"""
通过获取好友信息,判断用户是否还在线。
:return: bool,当返回为 True 时,在线;False 已断开连接。
"""
try:
if itchat.search_friends():
return True
except IndexError:
return False
return True
if _online(): return True # 如果在线,则直接返回 True
if not auto_login: # 不自动登录,则直接返回 False
print('微信已离线..')
return False
# hotReload = not config.get('is_forced_switch', False) # 切换微信号,重新扫码。
hotReload = False # 2019年9月27日15:31:22 最近保存最近登录状态出错,所以先设置每次都得扫码登录
loginCallback = init_data
exitCallback = exit_msg
try:
for _ in range(2): # 尝试登录 2 次。
if platform.system() in ('Windows', 'Darwin'):
itchat.auto_login(hotReload=hotReload,
loginCallback=loginCallback, exitCallback=exitCallback)
itchat.run(blockThread=True)
else:
# 命令行显示登录二维码。
itchat.auto_login(enableCmdQR=2, hotReload=hotReload, loginCallback=loginCallback,
exitCallback=exitCallback)
itchat.run(blockThread=True)
if _online():
print('登录成功')
return True
except Exception as exception: # 登录失败的错误处理。
sex = str(exception)
if sex == "'User'":
print('此微信号不能登录网页版微信,不能运行此项目。没有任何其它解决办法!可以换个号再试试。')
else:
print(sex)
delete_cache() # 清理缓存数据
print('登录失败。')
return False