python第三方库之幸运飞艇源码搭建itchat

安装itchat

幸运飞艇源码搭建Q【1152880099】
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)

猜你喜欢

转载自www.cnblogs.com/youdiansuan/p/11016188.html