昨天木子问我能不能做自动刷某音短视频,还要自动刷小哥哥,不是小哥哥就划走。
我心想,这女人真麻烦,怎么这么多事。
不好好工作天天想着小哥哥!
为了不得罪她,当时我就先答应了下来,然而实际上我把小哥哥变成了小姐姐,刷什么小哥哥,多没品味!
好了,话不多说,我们直接上代码!
首先导入需要使用的模块
import base64 import urllib import json import requests import sys
获取接口
获取 access_token 有效期一般有一个月
client_id = api_key client_secret = secret_key # 完整代码我都放在这个群了 872937351 # 直接加它领取 auth_url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret header_dict = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko', "Content-Type": "application/json" }
请求获取到token的接口
response_at = requests.get(auth_url, headers=header_dict) json_result = json.loads(response_at.text) access_token = json_result['access_token'] return access_token
调用人脸识别的接口,返回识别到的人脸列表。
headers ={ 'Content-Type': 'application/json; charset=UTF-8' } if pic_type == TYPE_IMAGE_NETWORK: image = pic_url image_type = 'URL' else: with open(pic_url, 'rb') as file: image = base64.b64encode(file.read()) image_type = 'BASE64' post_data ={ 'image': image, 'image_type': image_type, 'face_field': 'facetype,gender,age,beauty', # expression,faceshape,landmark,race,quality,glasses 'max_face_num': 2 } response_fi = requests.post(url_fi, headers=headers, data=post_data) json_fi_result = json.loads(response_fi.text)
如果人脸识别成功,返回人脸列表,否则返回None
if not json_fi_result or json_fi_result['error_msg'] != 'SUCCESS': return None else: return json_fi_result['result']['face_list']
人脸识别,返回人脸列表。
def parse_face_pic(pic_url, pic_type, access_token): url_fi = 'https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=' + access_token # 调用identify_faces,获取人脸列表 json_faces = identify_faces(pic_url, pic_type, url_fi) if not json_faces: return None else: return json_faces
解析人脸识别结果,判断颜值是否达标。
条件:性别女,颜值大于等于 70
def analysis_face(face_list): # 是否能找到漂亮小姐姐 find_plxjj = False if face_list: for face in face_list: # 判断是男、女 if face['gender']['type'] == 'female': age = face['age'] beauty = face['beauty'] if beauty >= 70: print('发现一个 ' + str(age) + ' 岁的美女,颜值为:%d,满足条件!' % beauty) find_plxjj = True break else: print('发现一个 ' + str(age) + ' 岁的女生,颜值为:%d,不及格,继续~' % beauty) continue return find_plxjj
App的应用包名和初始Activity
package_name = 'com.ss.android.ugc.aweme' activity_name = 'com.ss.android.ugc.aweme.splash.SplashActivity'
打开 Android 应用
def start_my_app(package_name, activity_name): os.popen('adb shell am start -n %s/%s' % (package_name, activity_name))
保存截图以及点赞
def save_video_met(screen_name, find_girl_num): img = Image.open(screen_name).convert('RGB') img.save("漂亮的小姐姐/DYGirl_%d.jpg" % find_girl_num) os.system("adb shell input tap 666 800")
向上划屏幕,播放下一段视频
def play_next_video(): os.system("adb shell input swipe 540 1300 540 500 100")
截图并修剪保存
def get_screen_shot_part_img(image_name): # 截图 os.system("adb shell /system/bin/screencap -p /sdcard/screenshot.jpg") os.system("adb pull /sdcard/screenshot.jpg %s" % image_name)