feat: add FacebookBot class to automate posting comments with images using uiautomator2
This commit is contained in:
@@ -78,10 +78,20 @@ class FacebookBot:
|
||||
comment_btn = btn
|
||||
break
|
||||
else:
|
||||
logging.info(f"Đã thấy bài viết thứ {current_post_count}, đang bỏ qua để tìm bài {post_index}...")
|
||||
# Vuốt qua bài viết hiện tại bằng 1 cú vuốt dài (70% màn hình)
|
||||
self.d.swipe_ext("up", scale=0.7)
|
||||
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"]
|
||||
center_x = (bounds["left"] + bounds["right"]) // 2
|
||||
|
||||
# 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)
|
||||
|
||||
current_post_count += 1
|
||||
continue
|
||||
|
||||
@@ -169,6 +179,14 @@ class FacebookBot:
|
||||
if send_btn.exists:
|
||||
send_btn.click()
|
||||
time.sleep(3)
|
||||
|
||||
# Dọn dẹp bộ nhớ cho điện thoại: xóa file ảnh ngay lập tức sau khi post xong
|
||||
if has_image:
|
||||
logging.info("Đang dọn dẹp file ảnh tạm trên điện thoại...")
|
||||
self.d.shell("rm -f /sdcard/Pictures/n8n_fb_*.jpg")
|
||||
# Cập nhật lại thư viện ảnh để nó xóa hẳn khỏi Gallery
|
||||
self.d.shell('am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/Pictures/')
|
||||
|
||||
return {"status": "success", "message": "Đã comment thành công!"}
|
||||
else:
|
||||
self.dump_ui_for_debug("error_fb_no_send_btn.xml")
|
||||
|
||||
Reference in New Issue
Block a user