Python学习之第三方模块(qrcode,itchat)

python支持第三方模块,可以下载导入第三方模块,直接应用

  • 1.qrcode
    python-qrcode是个用来生成二维码图片的第三方模块,依赖于 PIL 模块和 qrcode 库。
import qrcode
img = qrcode.make('http://www.baidu.com')
img.save('hello.png')

代码运行后,会在当前文件夹下生成一个,hello.png 图像文件,该文件为百度连接的二维码
在这里插入图片描述

  • 2.itchat
  • itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单。

给手机助手发消息–hello

import random
import time
import itchat
itchat.auto_login()
while True:
    itchat.send('hello',toUserName='filehelper')  ##给手机助手发消息--hello
    # itchat.send_file('/etc/passwd',toUserName='filehelper') ##给手机助手发文件--/etc/passwd
    time.sleep(random.randint(1,3)) ##每1~3秒发一次
friends = itchat.get_friends()
print(friends)
info = {}

查看微信里不同性别的好友人数

import itchat
itchat.auto_login()
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)

给文件助手发送消息,执行发送的内容
1.如果执行成功,显示执行结果
2.如果执行失败,显示执行失败

"""
给文件助手发送消息,执行发送的内容
    1.如果执行成功,显示执行结果
    2.如果执行失败,显示执行失败
"""
import itchat
import os
@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    if msg['ToUserName'] == 'filehelper':
        #获取要执行命令的内容
        command = msg['Content']
        print(command)
        #让电脑执行命令代码
        #如果执行成功,返回值为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()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值