feat: implement FacebookBot class for automated image posting and commenting via uiautomator2

This commit is contained in:
Victor Phan
2026-07-23 15:19:01 +07:00
parent 9ac7f1389e
commit 6acef907a8
3 changed files with 21 additions and 17 deletions
Binary file not shown.
+21 -17
View File
@@ -67,30 +67,34 @@ class FacebookBot:
c_desc_en = self.d(descriptionMatches="(?i)^comment$") c_desc_en = self.d(descriptionMatches="(?i)^comment$")
c_text_en = self.d(textMatches="(?i)^comment$") c_text_en = self.d(textMatches="(?i)^comment$")
btn = None # Lấy tất cả các nút có thể là nút Bình luận
if c_desc_vn.exists: btn = c_desc_vn candidates = []
elif c_text_vn.exists: btn = c_text_vn if c_desc_vn.exists: candidates.extend([c_desc_vn[i] for i in range(c_desc_vn.count)])
elif c_desc_en.exists: btn = c_desc_en if c_text_vn.exists: candidates.extend([c_text_vn[i] for i in range(c_text_vn.count)])
elif c_text_en.exists: btn = c_text_en if c_desc_en.exists: candidates.extend([c_desc_en[i] for i in range(c_desc_en.count)])
if c_text_en.exists: candidates.extend([c_text_en[i] for i in range(c_text_en.count)])
if btn and btn.exists: # Chỉ lấy những nút nằm dưới khu vực Header của Facebook (Y > 350)
btn = None
for c in candidates:
if c.info["bounds"]["bottom"] > 350:
btn = c
break
if btn:
if current_post_count == post_index: if current_post_count == post_index:
comment_btn = btn comment_btn = btn
break break
else: else:
logging.info(f"Đã thấy bài viết thứ {current_post_count}, đang đẩy nó ra khỏi màn hình để tìm bài {post_index}...") logging.info(f"Đã thấy bài viết thứ {current_post_count}, đang đẩy nó vào góc khuất để tìm bài {post_index}...")
bounds = btn[0].info["bounds"] bounds = btn.info["bounds"]
start_y = bounds["bottom"]
center_x = (bounds["left"] + bounds["right"]) // 2 center_x = (bounds["left"] + bounds["right"]) // 2
start_y = bounds["bottom"]
# Nếu nút đang nằm ở nửa dưới màn hình, vuốt nó lên sát mép trên # Vuốt đúng khoảng cách để đẩy nút Bình luận hiện tại lên tọa độ Y=200 (Vùng bị bỏ qua)
if start_y > 300: if start_y > 250:
self.d.swipe(center_x, start_y, center_x, 250, duration=0.4) self.d.swipe(center_x, start_y, center_x, 200, duration=0.4)
time.sleep(1) time.sleep(2)
# Bồi thêm một cú vuốt 400 pixel nữa để tống cổ hoàn toàn cái nút này khỏi viền trên màn hình
self.d.swipe(center_x, 600, center_x, 100, duration=0.3)
time.sleep(2)
current_post_count += 1 current_post_count += 1
continue continue