feat: implement FacebookBot class for automated group commenting using uiautomator2
This commit is contained in:
Binary file not shown.
@@ -39,14 +39,27 @@ class FacebookBot:
|
|||||||
self.d.shell(f'am start -a android.intent.action.VIEW -d "fb://group/{group_id}"')
|
self.d.shell(f'am start -a android.intent.action.VIEW -d "fb://group/{group_id}"')
|
||||||
time.sleep(8) # Đợi load giao diện group
|
time.sleep(8) # Đợi load giao diện group
|
||||||
|
|
||||||
# Tìm nút "Bình luận" của bài viết đầu tiên hiển thị
|
# Quét nút Bình luận, nếu không thấy thì vuốt xuống (vì ảnh bìa group che mất)
|
||||||
logging.info("Tìm nút Bình luận của bài viết đầu tiên...")
|
logging.info("Tìm nút Bình luận của bài viết đầu tiên...")
|
||||||
# Facebook dùng description hoặc text, thường là "Bình luận" hoặc "Comment"
|
comment_btn = None
|
||||||
comment_btn = self.d(descriptionContains="Bình luận")
|
|
||||||
if not comment_btn.exists:
|
|
||||||
comment_btn = self.d(descriptionContains="Comment")
|
|
||||||
|
|
||||||
if comment_btn.exists:
|
for _ in range(7): # Thử vuốt tối đa 7 lần
|
||||||
|
# Thử quét bằng Regex (Không phân biệt hoa thường) ở cả description và text
|
||||||
|
c_desc_vn = self.d(descriptionMatches="(?i).*bình luận.*")
|
||||||
|
c_text_vn = self.d(textMatches="(?i).*bình luận.*")
|
||||||
|
c_desc_en = self.d(descriptionMatches="(?i).*comment.*")
|
||||||
|
c_text_en = self.d(textMatches="(?i).*comment.*")
|
||||||
|
|
||||||
|
if c_desc_vn.exists: comment_btn = c_desc_vn; break
|
||||||
|
if c_text_vn.exists: comment_btn = c_text_vn; break
|
||||||
|
if c_desc_en.exists: comment_btn = c_desc_en; break
|
||||||
|
if c_text_en.exists: comment_btn = c_text_en; break
|
||||||
|
|
||||||
|
# Vuốt lên một chút
|
||||||
|
self.d.swipe_ext("up", scale=0.5)
|
||||||
|
time.sleep(1.5)
|
||||||
|
|
||||||
|
if comment_btn and comment_btn.exists:
|
||||||
comment_btn[0].click() # Click vào bài đầu tiên tìm thấy
|
comment_btn[0].click() # Click vào bài đầu tiên tìm thấy
|
||||||
else:
|
else:
|
||||||
self.dump_ui_for_debug("error_fb_no_comment_btn.xml")
|
self.dump_ui_for_debug("error_fb_no_comment_btn.xml")
|
||||||
|
|||||||
Reference in New Issue
Block a user