Python——第三方模块

注:需要联网才能实现第三方模块的导入

手动导入需要的模块

以qrcode模块为例,其他的同理,步骤如下:

  • file —>settings
    在这里插入图片描述
    在这里插入图片描述下载成功
    在这里插入图片描述
第三方模快的应用举例

例一:生成一张名为baidu.img的二维码,扫这张二维码会跳转到百度

import qrcode
img = qrcode.make('http://www.baidu.com')
img.save('baidu.img')

在这里插入图片描述

例二:当微信扫码后,会给手机助手一直输出’hello westos’

import random
import time
import itchat
hotReload = True
itchat.auto_login()
while True:
    itchat.send('hello westos',toUserName='filehelper')
    time.sleep(random.randint(1,3))

在这里插入图片描述

例三:产生的二维码会给手机助手发送文件/etc/passwd

import random
import time
import itchat
hotReload = True
itchat.auto_login()
while True:
    itchat.send_file('/etc/passwd',toUserName='filehelper')
    time.sleep(random.randint(1,3))

在这里插入图片描述
例四:

import itchat
hotReload = True
itchat.auto_login()

friends = itchat.get_friends()
# print(friends)
info = {}
for friend 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)

在这里插入图片描述
例五:手机扫码后可以在手机上输入命令linux系统执行

import os
import itchat

def text_reply(msg):
    if msg['ToUserName'] == 'filehelper':
        command = msg['Content']  #获取要执行的命令的内容
        if os.system(command) == 0:
            res = os.popen(command).read()
            result = '[返回值]-命令%s执行成功,执行结果: \n' + res
            itchat.send(result,'filehelper')
        else:
            result = '[返回值]-命令%s执行失败,请检查命令: \n' %(command)
            itchat.send(result,'filehelper')
itchat.auto_login()
itchat.run()

在这里插入图片描述

图灵机器人
import itchat
import requests

def get_tuling_respose(_info):
    print(_info)
    api_url = 'http://www.tuling123.com/openapi/api'
    data = {
        'key':'f90956d3a9f947be95ec28e02a52ce58',
        'info':_info,
        'userid':'lily'
    }
    res = requests.post(api_url,data).json()
    # print(res,type(res))
    print(res['text'])
    return (res['text'])

# get_tuling_respose('给我讲个笑话')
# get_tuling_respose('不好笑')

@itchat.msg_register(itchat.content.TEXT,isFriendChat=True)
def text_reply(msg):
    content = msg['Content']
    returnContent = get_tuling_respose(content)
    return returnContent

itchat.auto_login()
itchat.run()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值