py-第三方模块(itchat模块)

“”"

import itchat #第三方模块 需要网络下载
import time

1.给手机助手发送消息

itchat.auto_login()
#while True:
#给微信的手机助手发信息
itchat.send('hello',toUserName='filehelper')
     itchat.send_file('/etc/passwd',toUserName='filehelper')
     time.sleep(1)

2.统计你的好友的男女比例

friends = itchat.get_friends()
#print(friends)

info = {}
for friends in friends[1:]:
    if friends['Sex'] == 1:
        info['male'] = info.get('male',0) + 1
    elif friends['Sex'] == 2:
        info['female'] = info.get('female',0) + 1
    else:
        info['other'] = info.get('other',0) + 1
print(info)

“”"

“”"

import os
import itchat

@itchat.msg_register(itchat.content.TEXT,isFriendChat=True)
def text_reply(msg):
    if msg['ToUserName'] == 'filehelper':
        # 获取要执行的命令的内容
        command = msg['Content']
        # 让电脑执行命令代码
        # 如果执行成功,返回值为0
        if os.system(command) == 0:
            res = os.popen(command).read()
            result = '[返回值]-命令执行成功,执行结果:\n' +res
            itchat.send(result,'filehelper')

        # 如果命令执行失败
        else:
            result = '[返回值]-命令%s执行失败,请重新测试' %(command)
            itchat.send(result,'filehelper')
itchat.auto_login()
itchat.run()

“”"

“”"

import os
"""
在python中执行shell命令
判断命令是否执行成功
#返回值是0  执行成功
#返回值不为0 执行不成功
"""
print(os.system('ls'))
print(os.system('hostnamessssss'))

#保存命令执行的结果
res = os.popen('hostname').read()
print(res)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值