首页 / PYTHON / python第三方库itchat
python第三方库itchat
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python第三方库itchat,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1815字,纯文字阅读大概需要3分钟。
内容图文
![python第三方库itchat](/upload/InfoBanner/zyjiaocheng/802/17baebe27fa84444bded3c6477a95d3b.jpg)
- 安装itchat
pip install itchat
2.导包
import itchat
3.登陆操作
itchat.login() # 只是普通的登陆,并不具有缓存的功能
itchat.auto_login(hotReload=True) #会保留登陆状态,在短时间内不用重新登陆
- 给微信手机助手发消息
itchat.send('hello',toUserName='filehelper')
5.给微信助手发文件
#itchat.send_file('/etc/passwd',toUserName='filehelper')
2.统计你的好友的男女比例
friends = itchat.get_friends()
#print(friends)
info = {}
for friend in friends[1:]:
if friend['Sex'] == 1:
info['male'] = info.get('male',0) + 1
elif friend['Sex'] == 2:
info['female'] = info.get('female',0) + 1
else:
info['other'] = info.get('other',0) + 1
print(info)
3.
import os
#在python中执行shell命令
#1.可以判断命令是否执行成功
#返回值是0 执行成功
#返回值不为0 执行不成功
print(os.system('ls'))
#res = os.system('hostnameeeee')
#print(res)
#2.用来保存命令的执行结果
res = os.popen('hostname').read()
print(res)
4.图灵机器人微信聊天
import itchat
import requests
def get_tuling_reponse(_info):
print(_info)
api_url = 'http://www.tuling123.com/openapi/api' 注册图灵提供的url
data = {
'key':'28a1d488a7fe47b5b637b750a6f3d66b', 注册图灵机器人中的key
'info':_info,
'userid':'haha'
}
#发送数据到指定的网址,获取网址返回的数据
res = requests.post(api_url,data).json()
#print(res,type(res))
#给用户返回的内容
print(res['text'])
return (res['text'])
#get_tuling_reponse('给我讲个笑话')
#get_tuling_reponse('不好笑')
#时刻监控好友发送的文本信息,并且给与一个回复br/>@itchat.msg_register(itchat.content.text,isfriendchat=true)
def text_repky(msg):
获取好友发送的文本信息
#返回文本信息
content = msg['Content']
#将好友的消息发送给机器人去处理,处理的结果就是返回给好友的信息
returnContent = get_tuling_reponse(content)
return returnContent
itchat.auto_login()
itchat.run()
内容总结
以上是互联网集市为您收集整理的python第三方库itchat全部内容,希望文章能够帮你解决python第三方库itchat所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。