Python 蚂蚁森林自动收集能量脚本

不需要root权限,不需要xposed框架支持

演示视频

加好友一起偷能量吗(疯狂暗示)
[email protected]

1.原理

使用adb指令模拟操作屏幕

2.准备

2.1 安装python3环境

  • 建议安装到默认路径,否则添加安装路径到环境变量
  • ubuntu一键安装:sudo apt-get install python3

2.2 安装adb环境(windows需要将adb路径添加到环境变量)

  • windows:很简单,参考其他博文
  • ubuntu一键安装:sudo apt-get install adb

2.3 手机打开usb调试

  • 小米手机需要打开允许usb调试操作屏幕
  • 提前得知自己手机屏幕分辨率(如:2340*1080)

3.偷能量

3.1 修改参数

3.11 分辨率改成自己的
# 屏幕分辨率
base_x = 1080
base_y = 2340
3.12 采集区域,默认不用改,失效可以微调
x_start = 105
x_end = 880
y_start = 480
y_end = 840
3.13 排名根据实际情况修改
# 输入自己排名
myRank = 2
# 输入好友总数
friendsNum = 49
3.14 完整代码
import os
import time

# 屏幕分辨率
base_x = 1080
base_y = 2340

x_start = 105
x_end = 880
y_start = 480
y_end = 840

# 输入自己排名
myRank = 2
# 输入好友总数
friendsNum = 49


def tap_screen(tap_x, tap_y):
    cmd = 'adb shell input tap {x1} {y1}'.format(
        x1=tap_x / 1080 * base_x,
        y1=tap_y / 2340 * base_y,
    )
    os.system(cmd)


def swipe_screen(tap_sx, tap_sy, tap_ex, tap_ey, timeLen):
    cmd = 'adb shell input swipe {x1} {y1} {x2} {y2} {times}'.format(
        x1=tap_sx / 1080 * base_x,
        y1=tap_sy / 2340 * base_y,
        x2=tap_ex / 1080 * base_x,
        y2=tap_ey / 2340 * base_y,
        times=timeLen
    )
    os.system(cmd)
    # print(tap_sx, tap_sy, tap_ex, tap_ey, timeLen)


def init():
    tap_screen(548, 339)
    tap_screen(548, 339)
    # 收自己的蚂蚁能量
    print("正在收取自己的蚂蚁能量")
    getGreenEnergy()
    print("收取自己的蚂蚁能量结束")


def getGreenEnergy():
    for x in range(x_start, x_end, 100):
        for y in range(y_start, y_end, 100):
            tap_screen(x, y)


def changeUser():
    # 滑动到排行榜第一位
    swipe_screen(550, 1615, 250, 918, 1000)
    # 第十次展开更多好友列表
    for i in range(10):
        if i != myRank:
            print("第{}位朋友".format(1 + i))
            # 点击进入朋友蚂蚁森林界面
            tap_screen(650, 2230)
            # 偷蚂蚁能量
            getGreenEnergy()
            # 退出该朋友界面
            swipe_screen(0, 900, 370, 900, 500)
            print("收取第{}位朋友的蚂蚁能量结束".format(1 + i))
        # 再次滑动固定距离
        swipe_screen(550, 1155, 550, 1155 - 205, 1000)

    # 点开查看更多好友
    tap_screen(650, 2180)
    time.sleep(2)
    swipe_screen(550, 1155, 550, 1155 - 209, 1000)

    for i in range(friendsNum - 10):
        if i != myRank:
            print("第{}位朋友".format(11 + i))
            # 点击进入朋友蚂蚁森林界面
            tap_screen(650, 2230)
            # 偷蚂蚁能量
            getGreenEnergy()
            # 退出该朋友界面

            swipe_screen(0, 900, 370, 900, 500)
            print("收取第{}位朋友的蚂蚁能量结束".format(11 + i))
        # 再次滑动固定距离
        swipe_screen(550, 1155, 550, 1155 - 209, 1000)


if __name__ == '__main__':
    init()
    changeUser()

发布了100 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_39827677/article/details/105134734