feat: implement FacebookBot class for automated image posting and commenting via uiautomator2
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -67,30 +67,34 @@ class FacebookBot:
|
||||
c_desc_en = self.d(descriptionMatches="(?i)^comment$")
|
||||
c_text_en = self.d(textMatches="(?i)^comment$")
|
||||
|
||||
btn = None
|
||||
if c_desc_vn.exists: btn = c_desc_vn
|
||||
elif c_text_vn.exists: btn = c_text_vn
|
||||
elif c_desc_en.exists: btn = c_desc_en
|
||||
elif c_text_en.exists: btn = c_text_en
|
||||
# Lấy tất cả các nút có thể là nút Bình luận
|
||||
candidates = []
|
||||
if c_desc_vn.exists: candidates.extend([c_desc_vn[i] for i in range(c_desc_vn.count)])
|
||||
if c_text_vn.exists: candidates.extend([c_text_vn[i] for i in range(c_text_vn.count)])
|
||||
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:
|
||||
comment_btn = btn
|
||||
break
|
||||
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}...")
|
||||
bounds = btn[0].info["bounds"]
|
||||
start_y = bounds["bottom"]
|
||||
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.info["bounds"]
|
||||
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
|
||||
if start_y > 300:
|
||||
self.d.swipe(center_x, start_y, center_x, 250, duration=0.4)
|
||||
time.sleep(1)
|
||||
|
||||
# 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)
|
||||
# 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 > 250:
|
||||
self.d.swipe(center_x, start_y, center_x, 200, duration=0.4)
|
||||
time.sleep(2)
|
||||
|
||||
current_post_count += 1
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user