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,29 +67,33 @@ 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)
|
|
||||||
|
|
||||||
# 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)
|
time.sleep(2)
|
||||||
|
|
||||||
current_post_count += 1
|
current_post_count += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user