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

  • 例1:qrcode
import qrcode
img = qrcode.make('http://www.baidu.com')
img.save('hello.png')

代码运行后,会在当前文件夹下生成一个,hello.png 图像文件,该文件为百度连接的二维码
part_58:python_第三方模块

  • 例:itchat
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 = {}
"""
# _*_coding:utf-8 _*_
Name:第三方模块.py
Date:4/8/19
Author:LiMin
Connect:[email protected]
Desc:
"""
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)
"""
# _*_coding:utf-8 _*_
Name:第三方模块01.py
Date:4/8/19
Author:LiMin
Connect:[email protected]
Desc:
"""
"""
给文件助手发送消息,执行发送的内容
    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()

相关文章:

  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2021-07-11
  • 2021-11-13
  • 2021-10-25
  • 2022-12-23
猜你喜欢
  • 2021-04-06
  • 2021-09-14
  • 2022-12-23
  • 2021-12-06
  • 2022-01-05
  • 2021-12-02
相关资源
相似解决方案