
find what cause this error and give the solution. i pasted a...
Prompt
find what cause this error and give the solution. i pasted all 2 files and a output below. import subprocess import time import re P1_X, P1_Y = 664, 779 P2_X, P2_Y = 664, 932 P3_X, P3_Y = 664, 1073 P4_X, P4_Y = 664, 1212 SAVE_X, SAVE_Y = 487, 1320 VALID_ROW_STARTS_WITH = "add up to" DONE_ROW_KEYWORDS = ["added", "edit"] TOTAL_TEAMS = 40 MAX_FIND_ATTEMPTS = 5 EXPECTED_TOP_AFTER_SCROLL = 500 SCROLL_TOLERANCE = 15 MIN_CORRECTION_PX = 26 MAX_CORRECTION_PX = 320 MAX_CORRECTION_ATTEMPTS = 6 RECOVERY_SWIPE_PX = 240 TAP_SAFE_MIN_Y = 460 TAP_SAFE_MAX_Y = 1240 STUCK_TOLERANCE_PX = 2 # if a swipe moves the row less than this, the list can't scroll further def tap(x, y): subprocess.run(f"adb shell input tap {x} {y}", shell=True) def scroll_to_next_team(): subprocess.run("adb shell input swipe 608 919 608 465 2000", shell=True) def correction_swipe(offset_pixels): magnitude = abs(int(offset_pixels)) if magnitude < MIN_CORRECTION_PX: magnitude = MIN_CORRECTION_PX if magnitude > MAX_CORRECTION_PX: magnitude = MAX_CORRECTION_PX start_y = 700 end_y = start_y - magnitude if offset_pixels > 0 else start_y + magnitude end_y = max(min(end_y, 1150), 250) duration = max(300, min(900, magnitude * 3)) subprocess.run(f"adb shell input swipe 608 {start_y} 608 {end_y} {duration}", shell=True) def recovery_swipe_down(): subprocess.run(f"adb shell input swipe 608 600 608 {600 + RECOVERY_SWIPE_PX} 700", shell=True) def get_screen_layout_text(): subprocess.run("adb shell uiautomator dump /sdcard/ui_dump.xml", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run("adb pull /sdcard/ui_dump.xml ui_dump.xml", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) try: with open("ui_dump.xml", "r", encoding="utf-8") as f: return f.read() except FileNotFoundError: return "" def find_all_rows(layout_text): pattern = re.compile(r'text="([^"]*)"[^>]*bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"') valid_matches, done_matches = [], [] for match in pattern.finditer(layout_text): text, left, top, right, bottom = match.groups() text_lower = text.strip().lower() if not text_lower: continue box = (int(left), int(top), int(right), int(bottom)) if all(keyword in text_lower for keyword in DONE_ROW_KEYWORDS): done_matches.append(box) elif text_lower.startswith(VALID_ROW_STARTS_WITH): valid_matches.append(box) valid_matches.sort(key=lambda b: b[1]) done_matches.sort(key=lambda b: b[1]) return valid_matches, done_matches def box_to_tap_position(box): left, top, right, bottom = box return (right - 40, (top + bottom) // 2) # --- end-of-list detection helpers --- def get_row_signature(): """Bounds of every visible team row - used to tell whether a swipe actually moved the list.""" layout_text = get_screen_layout_text() valid_rows, done_rows = find_all_rows(layout_text) return tuple(sorted(valid_rows + done_rows, key=lambda b: (b[1], b[0]))) def signatures_match(sig_before, sig_after): """True only if both snapshots show the same rows at the same positions (within tolerance).""" if not sig_before or len(sig_before) != len(sig_after): return False return all( abs(coord_a - coord_b) <= STUCK_TOLERANCE_PX for box_a, box_b in zip(sig_before, sig_after) for coord_a, coord_b in zip(box_a, box_b) ) def find_topmost_row(): for attempt in range(MAX_FIND_ATTEMPTS): layout_text = get_screen_layout_text() valid_rows, done_rows = find_all_rows(layout_text) if valid_rows and done_rows: return ("valid", valid_rows[0]) if valid_rows[0][1] <= done_rows[0][1] else ("done", done_rows[0]) if valid_rows: return ("valid", valid_rows[0]) if done_rows: return ("done", done_rows[0]) print(f" No row visible yet (attempt {attempt + 1}/{MAX_FIND_ATTEMPTS}), waiting...") time.sleep(1) return (None, None) def align_row_to_anchor(): previous_top = None for attempt in range(MAX_CORRECTION_ATTEMPTS): layout_text = get_screen_layout_text() valid_rows, done_rows = find_all_rows(layout_text) all_rows = valid_rows + done_rows if not all_rows: print(f" No row visible - recovery down-swipe ({attempt + 1}/{MAX_CORRECTION_ATTEMPTS}).") recovery_swipe_down() time.sleep(2) previous_top = None continue nearest_top = min(all_rows, key=lambda b: abs(b[1] - EXPECTED_TOP_AFTER_SCROLL))[1] offset = nearest_top - EXPECTED_TOP_AFTER_SCROLL if abs(offset) <= SCROLL_TOLERANCE: print(f" Row aligned at top={nearest_top} (offset {offset}px).") return True # NEW: identical position after a correction swipe = list can't move -> accept it if previous_top is not None and abs(nearest_top - previous_top) <= STUCK_TOLERANCE_PX: print(f" Swipe did not move the list (row stuck at top={nearest_top}) - " f"end of list, accepting position.") return True print(f" Row off by {offset}px - correcting (attempt {attempt + 1}/{MAX_CORRECTION_ATTEMPTS}).") correction_swipe(offset) time.sleep(2) previous_top = nearest_top return False def process_current_team(): row_type, box = find_topmost_row() if row_type == "valid": tap_x, tap_y = box_to_tap_position(box) if tap_y < TAP_SAFE_MIN_Y or tap_y > TAP_SAFE_MAX_Y: print(f" 'Add' row at y={tap_y} outside safe band - skipping this team.") return False print(f" Found 'Add' row at ({tap_x}, {tap_y}), tapping it.") tap(tap_x, tap_y) return True if row_type == "done": print(" Team already has backups - skipping.") return False print(" Could not find any row - skipping this team, no taps made.") return False print("Robot Ready! Open Dream11 on Team 1.") input("Press ENTER in this command window to start...") time.sleep(1) align_row_to_anchor() tapped_count = 0 for team in range(1, TOTAL_TEAMS + 1): print(f"--> Processing Team {team} of {TOTAL_TEAMS}...") tapped_add = process_current_team() time.sleep(3) if tapped_add: tap(P1_X, P1_Y) time.sleep(0.4) tap(P2_X, P2_Y) time.sleep(0.4) tap(P3_X, P3_Y) time.sleep(0.4) tap(P4_X, P4_Y) time.sleep(0.4) tap(SAVE_X, SAVE_Y) tapped_count += 1 time.sleep(3) else: print(f" Skipping player selection and Save for Team {team}.") if team == TOTAL_TEAMS: break # nothing left to position after the last team # NEW: compare screen before/after the big swipe - identical means the list can't scroll further sig_before = get_row_signature() scroll_to_next_team() time.sleep(3) sig_after = get_row_signature() if signatures_match(sig_before, sig_after): print(" List did not move after swipe - end of list, skipping anchor alignment.") elif not align_row_to_anchor(): print(" Warning: could not align row - continuing anyway.") print(f"ALL {TOTAL_TEAMS} TEAMS COMPLETED! Backups tapped on {tapped_count} team(s).") Robot Ready! Open Dream11 on Team 1. Press ENTER in this command window to start... No row visible - recovery down-swipe (1/6). adb.exe: more than one device/emulator No row visible - recovery down-swipe (2/6). adb.exe: more than one device/emulator No row visible - recovery down-swipe (3/6). adb.exe: more than one device/emulator No row visible - recovery down-swipe (4/6). adb.exe: more than one device/emulator No row visible - recovery down-swipe (5/6). adb.exe: more than one device/emulator No row visible - recovery down-swipe (6/6). adb.exe: more than one device/emulator --> Processing Team 1 of 40... No row visible yet (attempt 1/5), waiting... No row visible yet (attempt 2/5), waiting... No row visible yet (attempt 3/5), waiting... No row visible yet (attempt 4/5), waiting... No row visible yet (attempt 5/5), waiting... Could not find any row - skipping this team, no taps made. Skipping player selection and Save for Team 1. adb.exe: more than one device/emulator ============================================ QUICK START (Screen off + Always on top + Fixed port) ============================================ Turning these ON for this session: - Screen OFF while mirroring - Always on top Now connecting using the fixed port (5555)... Make sure your phone Wireless debugging is turned ON and phone is on the same WiFi as this PC. * daemon not running; starting now at tcp:5037 * daemon started successfully connected to 192.168.0.102:5555 scrcpy 4.1 <https://github.com/Genymobile/scrcpy> INFO: ADB device found: INFO: --> (tcpip) 192.168.0.102:5555 device SM_A055F INFO: (tcpip) adb-R9ZX501E2ZZ-Ostytq._adb-tls-connect._tcp device SM_A055F C:\Main Folder\scrcpy-win64-v4.1\scrcpy-win64-v4...d, 0 skipped. 30.6 MB/s (733706 bytes in 0.023s) [server] INFO: Device: [samsung] samsung SM-A055F (Android 15) INFO: Renderer: direct3d11 [server] INFO: Device display turned off INFO: Texture: 720x1600