python小玩意

import requests
import base64
import itchat
from itchat.content import *

def orc_look(filePath):
    host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=tSeFPh0pvmWbtEY5SbidzNWT&client_secret=q9YwDFUT4y85bglQPLkoFvA0boZBX5C5'
    access_token = ""
    response = requests.get(host)
    if response:
        access_token = response.json()["access_token"]
    with open(filePath, 'rb') as f:
        image_data = f.read()
        base64_ima = base64.b64encode(image_data)
        data = {
            'image': base64_ima
        }
        headers = {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
        url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=" + str(access_token)
        r = requests.post(url, params=headers, data=data).json()
        list = []  
        res = []  
        for word in r['words_result']:
            list.append(word['words'])
        if "16计算机科学与技术-4班未打卡学生名单" in list:
            for i in list:
                length = len(i)
                if length <= 3 and length >= 2:
                    if not '1' in i:
                        res.append(i)
            res.pop(0)
        return res


@itchat.msg_register([TEXT, PICTURE], isGroupChat=True)
def getPicture(msg):
    print(msg['User']['NickName'])
    if msg['User']['NickName'] == "互联网16级大四副班长群":
        if msg['Type'] == "Picture":
            filePath = "/home/retemin/images" + msg['FileName']
            msg.download(filePath)
            list = orc_look(filePath)
            if len(list)>0:
                for i in list:
                   Nickname =  itchat.search_friends(remarkName=i)
                   if Nickname:
                        UserName = Nickname[0]["UserName"]
                        itchat.send_msg("记得打卡",toUserName=UserName)
if __name__ == '__main__':
    itchat.auto_login(enableCmdQR=2,hotReload=True)
    itchat.run()


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值