feat: create FacebookBot class for automating group comments using uiautomator2
This commit is contained in:
@@ -38,6 +38,7 @@ class FacebookBot:
|
||||
# Dùng lệnh ADB shell để mở thẳng Deep Link của Group
|
||||
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
|
||||
self.dump_ui_for_debug("fb_step1_open_group.xml")
|
||||
|
||||
# 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...")
|
||||
@@ -58,9 +59,11 @@ class FacebookBot:
|
||||
# Vuốt lên một chút
|
||||
self.d.swipe_ext("up", scale=0.5)
|
||||
time.sleep(1.5)
|
||||
self.dump_ui_for_debug("fb_step2_scrolling.xml")
|
||||
|
||||
if comment_btn and comment_btn.exists:
|
||||
comment_btn[0].click() # Click vào bài đầu tiên tìm thấy
|
||||
self.dump_ui_for_debug("fb_step3_clicked_comment.xml")
|
||||
else:
|
||||
self.dump_ui_for_debug("error_fb_no_comment_btn.xml")
|
||||
return {"status": "error", "message": "Không tìm thấy nút Bình luận. Đã lưu dump UI."}
|
||||
@@ -88,6 +91,7 @@ class FacebookBot:
|
||||
if photo_btn.exists:
|
||||
photo_btn.click()
|
||||
time.sleep(3)
|
||||
self.dump_ui_for_debug("fb_step5_camera_opened.xml")
|
||||
|
||||
# Chọn ảnh đầu tiên trong thư viện (vừa mới push vào)
|
||||
# Facebook gallery thường có checkbox hoặc chỉ cần click vào vùng ảnh
|
||||
@@ -95,6 +99,7 @@ class FacebookBot:
|
||||
if gallery_images.count >= 2:
|
||||
gallery_images[1].click() # Bỏ qua icon đầu tiên thường là icon camera
|
||||
time.sleep(1)
|
||||
self.dump_ui_for_debug("fb_step6_image_selected.xml")
|
||||
|
||||
# Nút Xong / Done
|
||||
done_btn = self.d(textContains="Xong")
|
||||
|
||||
Reference in New Issue
Block a user