Created
December 12, 2021 17:20
-
-
Save YashMakan/8dbbde4735bdbb534682233f3d3c6b58 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
import cv2, subprocess | |
def adb(command): | |
proc = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE, shell=True) | |
(out, _) = proc.communicate() | |
return out.decode('utf-8') | |
def image_position(small_image, big_image): | |
img_rgb = cv2.imread(big_image) | |
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) | |
template = cv2.imread(small_image, 0) | |
height, width = template.shape[::] | |
res = cv2.matchTemplate(img_gray, template, cv2.TM_SQDIFF) | |
_, _, top_left, _ = cv2.minMaxLoc(res) | |
bottom_right = (top_left[0] + width, top_left[1] + height) | |
return (top_left[0]+bottom_right[0])//2, (top_left[1]+bottom_right[1])//2 | |
def swipe(start_x, start_y, end_x, end_y, duration_ms): | |
adb("adb shell input swipe {} {} {} {} {}".format(start_x, start_y, end_x, end_y, duration_ms)) | |
def click(tap_x, tap_y): | |
adb("adb shell input tap {} {}".format(tap_x, tap_y)) | |
def take_screenshot(final): | |
adb(f"adb exec-out screencap -p > ./images/{final}.png") | |
def send_sms(number, body): | |
adb(f'adb shell am start -a android.intent.action.SENDTO -d sms:{number} --es sms_body "{body}" --ez exit_on_sent true') | |
def call(number): | |
adb(f"adb shell am start -a android.intent.action.CALL -d tel:{number}") | |
def download(path, output_path): | |
adb(f"adb pull {path} {output_path}") #/sdcard/xxx.mp4 | |
def remove(path): | |
adb(f"adb shell rm {path}") #/sdcard/... | |
def screen_record(name, time): | |
adb(f"adb shell screenrecord /sdcard/{name} --time-limit {time}") | |
download(f"/sdcard/{name}",f"./mobile/{name}") | |
remove(f"/sdcard/{name}") | |
def send_whatsapp_message(phone, message): | |
adb(f'adb shell am start -a android.intent.action.VIEW -d "https://api.whatsapp.com/send?phone={phone}"') | |
adb('ping 127.0.0.1 -n 2 > nul') | |
adb(f'adb shell input text "{message}"') | |
adb('adb shell keyevent 22') | |
adb('adb shell keyevent 22') | |
adb('adb shell input keyevent 22') | |
adb('adb shell input keyevent 22') | |
adb('adb shell input keyevent 66') | |
def switch_phone_on_off(): | |
adb("adb shell input keyevent 26") | |
switch_phone_on_off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment