zoukankan      html  css  js  c++  java
  • Python|抖音机器人,论如何在抖音上找到漂亮小姐姐?

    只有想不到,没有做不到,最近抖音风靡好友圈,马上就有技术宅本着“代码改变世界”的理念开始了搞事之路。

    需要注意的事,漂亮不漂亮没有明确的界限,每个人都有每个人的审美,只有外表而没有心灵的美也是空洞的。该项目只是作者出于搞怪以及兴趣的目的去做的,初衷只是通过这个项目和大家交流技术,请勿乱喷。

    前言

          本文参考github地址为:https://github.com/wangshub/Douyin-Bot

      为了找到漂亮小姐姐,作者用 Python + ADB 做了一个 Python 抖音机器人 Douyin-Bot。相信之前微信“跳一跳”风靡的时候,就有小伙伴听说过利用Python和ADB进行刷分的操作,本文里涉及的项目的原理与其相似,不过引入了人脸识别库,进行了对应的操作。


     特性

    1. 自动翻页
    2. 颜值检测
    3. 人脸识别
    4. 自动点赞
    5. 自动关注
    6. 随机防Ban
    7. 自动回复

    原理

    • 打开《抖音短视频》APP,进入主界面
    • 获取手机截图,并对截图进行压缩 (Size < 1MB);
    • 请求人脸识别API;
    • 解析返回的人脸 Json 信息,对人脸检测切割;
    • 当颜值大于门限值 BEAUTY_THRESHOLD时,点赞并关注;
    • 下一页,返回第一步;

    douyin-bot.py:

    # -*- 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
    except Exception as ex:
        print(ex)
        print('请将脚本放在项目根目录中运行')
        print('请检查项目根目录中的 common 文件夹是否存在')
        exit(1)
    
    VERSION = "0.0.1"
    
    # 我申请的 Key,随便用,嘻嘻嘻
    # 申请地址 http://ai.qq.com
    AppID = '1106858595'
    AppKey = 'bNUNgOpY6AeeJjFu'
    
    DEBUG_SWITCH = True
    FACE_PATH = 'face/'
    
    adb = auto_adb()
    adb.test_device()
    config = config.open_accordant_config()
    
    # 审美标准
    BEAUTY_THRESHOLD = 80
    
    
    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 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 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)
    
            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 beauty > BEAUTY_THRESHOLD:
                    print('发现漂亮妹子!!!')
                    thumbs_up()
                    follow_user()
    
            else:
                print(rsp)
                continue
    
    
    if __name__ == '__main__':
        try:
            # yes_or_no()
            main()
        except KeyboardInterrupt:
            adb.run('kill-server')
            print('
    谢谢使用', end='')
            exit(0)
    

    使用教程

    1. 获取源码:git clone https://github.com/wangshub/Douyin-Bot.git
    2. 进入源码目录: cd Douyin-Bot
    3. 安装依赖: pip install -r requirements.txt
    4. 运行程序:python douyin-bot.py


  • 相关阅读:
    python技巧
    tikz vfill vfil
    知之为知之,不知为不知
    newPost
    欢迎使用 WordPress 3.2.1 for SAE
    校正oracle,mysql,hive,postgresql,greenplum 记录数分析命令
    Hive 分区表&分区字段
    oracle 建表、主键、分区
    使用TortoiseSVN 客户端的一些问题
    jquery bankInput银行卡账号格式化
  • 原文地址:https://www.cnblogs.com/jlutiger/p/9115560.html
Copyright © 2011-2022 走看看