1 Star 0 Fork 2

wateremh / doudouBot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
douyin-bot.py 5.20 KB
一键复制 编辑 原始数据 按行查看 历史
Gogs 提交于 2018-06-04 22:55 . first commit
# -*- coding: utf-8 -*-
import sys
import random
import time
from PIL import Image
if sys.version_info.major != 3:
print('Please run under Python3')
exit(1)
try:
from common import debug, config, screenshot, UnicodeStreamFilter
from common.auto_adb import auto_adb
from common import apiutil
from common.compression import resize_image,cut_image
except Exception as ex:
print(ex)
print('请将脚本放在项目根目录中运行')
print('请检查项目根目录中的 common 文件夹是否存在')
exit(1)
VERSION = "0.0.1"
# 我申请的 Key,随便用,嘻嘻嘻
# 申请地址 http://ai.qq.com
AppID = '1106875317'
AppKey = 'h8tQ7eTmVPImaysn'
DEBUG_SWITCH = True
FACE_PATH = 'face/'
RESULT_FILE_PATH="result/account.txt"
adb = auto_adb()
adb.test_device()
config = config.open_accordant_config()
# 审美标准
BEAUTY_THRESHOLD = 79
# 最小年龄
GIRL_MIN_AGE = 18
def yes_or_no():
"""
检查是否已经为启动程序做好了准备
"""
while True:
yes_or_no = str(input('请确保手机打开了 ADB 并连接了电脑,'
'然后打开手机软件,确定开始?[y/n]:'))
if yes_or_no == 'y':
break
elif yes_or_no == 'n':
print('谢谢使用', end='')
exit(0)
else:
print('请重新输入')
def _random_bias(num):
"""
random bias
:param num:
:return:
"""
print('num = ', num)
return random.randint(-num, num)
def next_page():
"""
翻到下一页
:return:
"""
cmd = 'shell input touchscreen swipe {x1} {y1} {x2} {y2} {duration}'.format(
x1=config['center_point']['x'],
y1=config['center_point']['y']+config['center_point']['ry'],
x2=config['center_point']['x'],
y2=config['center_point']['y'],
duration=200
)
adb.run(cmd)
time.sleep(1.5)
def follow_user():
"""
关注用户
:return:
"""
cmd = 'shell input tap {x} {y}'.format(
x=config['follow_bottom']['x'] + _random_bias(10),
y=config['follow_bottom']['y'] + _random_bias(10)
)
adb.run(cmd)
time.sleep(0.5)
def thumbs_up():
"""
点赞
:return:
"""
cmd = 'shell input tap {x} {y}'.format(
x=config['star_bottom']['x'] + _random_bias(10),
y=config['star_bottom']['y'] + _random_bias(10)
)
adb.run(cmd)
time.sleep(0.5)
def back():
cmd="shell input keyevent 4 "
adb.run(cmd)
def getUserProfile():
"""
获取抖音账号
:return:
"""
cmd = 'shell input tap {x} {y}'.format(
x=config['user_bottom']['x'] + _random_bias(10),
y=config['user_bottom']['y'] + _random_bias(10)
)
adb.run(cmd)
time.sleep(0.5)
screenshot.getUserImage()
#参数 左上右下
cut_image('user_profile.png', 'user.png', 0,560,700,600)
with open('user.png', 'rb') as bin_data:
user_image = bin_data.read()
ai_tools = apiutil.AiPlat(AppID, AppKey)
user_data = ai_tools.getUserData(user_image)
for textData in user_data['data']['item_list']:
if "抖音号" in textData['itemstring']:
AddDouYinAccount(textData['itemstring'])
def AddDouYinAccount(accountNum):
file = RESULT_FILE_PATH
with open(file, 'a+') as f:
f.write(accountNum + '\n') # 加\n换行显示
def main():
"""
main
:return:
"""
print('程序版本号:{}'.format(VERSION))
print('激活窗口并按 CONTROL + C 组合键退出')
debug.dump_device_info()
screenshot.check_screenshot()
while True:
next_page()
time.sleep(1)
screenshot.pull_screenshot()
resize_image('autojump.png', 'optimized.png', 1024*1024)
with open('optimized.png', 'rb') as bin_data:
image_data = bin_data.read()
ai_obj = apiutil.AiPlat(AppID, AppKey)
rsp = ai_obj.face_detectface(image_data, 0)
print(rsp)
major_total = 0
minor_total = 0
if rsp['ret'] == 0:
beauty = 0
for face in rsp['data']['face_list']:
print(face)
face_area = (face['x'], face['y'], face['x']+face['width'], face['y']+face['height'])
print(face_area)
img = Image.open("optimized.png")
cropped_img = img.crop(face_area).convert('RGB')
cropped_img.save(FACE_PATH + face['face_id'] + '.png')
# 性别判断
if face['beauty'] > beauty and face['gender'] < 50:
beauty = face['beauty']
if face['age'] > GIRL_MIN_AGE:
major_total += 1
else:
minor_total += 1
# 是个美人儿~关注点赞走一波
if beauty > BEAUTY_THRESHOLD and major_total > minor_total:
print('发现漂亮妹子!!!')
#thumbs_up()
#follow_user()
getUserProfile()
back()
else:
print(rsp)
continue
if __name__ == '__main__':
try:
# yes_or_no()
main()
except KeyboardInterrupt:
adb.run('kill-server')
print('谢谢使用')
exit(0)
Python
1
https://gitee.com/wateremh/doudouBot.git
git@gitee.com:wateremh/doudouBot.git
wateremh
doudouBot
doudouBot
master

搜索帮助