Created
August 15, 2019 13:56
-
-
Save sekkr1/df413f84a7300b6f700b57bf8ce3e1f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# A script to auto scroll a phone using ADB | |
# | |
from subprocess import check_output, call | |
from argparse import ArgumentParser | |
from os import system | |
from random import randint | |
from time import sleep | |
# Swipe phone using ADB | |
def swipe(x1, y1, x2, y2, speed=''): | |
call(['adb', 'shell', 'input', 'touchscreen', | |
'swipe', str(x1), str(x2), str(y1), str(y2), str(speed)]) | |
# Setup arguments | |
parser = ArgumentParser( | |
prog='AutoScroll.py', description='A script to auto scroll in any given direction') | |
for direction in 'top', 'bottom', 'left', 'right': | |
parser.add_argument( | |
f'-{direction[0]}', f'--{direction}-margin', default=0, type=int, help=f'The margin for {direction} side, given as percentages') | |
parser.add_argument( | |
'direction', help='Direction to scroll in, currently only support up-down(U-D) and down-up(D-U)') | |
parser.add_argument('--time', default=1, type=float, | |
help='Time to wait between scrolls') | |
parser.add_argument('-v', '--verbose', action='store_true', | |
help='Print each time a swipe is being run') | |
parser.add_argument('--randomize', action='store_true', | |
help='Randomize scroll time, start and end points to evade anti bot schemes') | |
parser.add_argument('--speed', default=100, type=int, | |
help='Speed of scrolls in milliseconds') | |
args = parser.parse_args() | |
if args.direction != 'U-D' and args.direction != 'D-U': | |
exit('Please input a valid direction!') | |
# Get phone screen size | |
screen_size = check_output( | |
['adb', 'shell', 'wm', 'size']).decode().split(' ')[-1] | |
width, height = map(int, screen_size.split('x')) | |
# Calculate boundaries | |
left = width * (args.left_margin / 100) | |
right = width - (width * args.right_margin / 100) | |
top = height * (args.top_margin / 100) | |
bottom = height - height * (args.bottom_margin / 100) | |
margin_width = right - left | |
margin_height = bottom - top | |
# Start swiping | |
x = (left + right) / 2 | |
i = 1 | |
while True: | |
if args.verbose: | |
print(f'Swipe for the {i} time') | |
if args.randomize: | |
# Calculate randomized start and end locations within boundaries | |
x1 = randint(left, right) | |
x2 = randint(max(x1 - margin_width * 0.05, left), | |
min(x1 + margin_width * 0.05, right)) | |
y1 = randint(top, top + margin_height * 0.08) | |
y2 = randint(bottom, bottom - margin_height * 0.08) | |
time = randint(80, 300) | |
if direction == 'D-U': | |
# Reverse direction if down-up | |
y1, y2 = y2, y1 | |
swipe(x1, y1, x2, y2, time) | |
if args.direction == 'U-D': | |
swipe(x, top, x, bottom, args.speed) | |
elif args.direction == 'D-U': | |
swipe(x, bottom, x, top, args.speed) | |
i += 1 | |
sleep(args.time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment