feat: add FastAPI server and Facebook automation bot for device-based task execution

This commit is contained in:
Victor Phan
2026-07-23 14:50:39 +07:00
parent 384be28c2b
commit fea2789bd4
2 changed files with 54 additions and 13 deletions
+18 -7
View File
@@ -14,9 +14,15 @@ class FacebookBot:
logging.warning("Không có file ảnh cục bộ để đẩy lên điện thoại.")
return False
import uuid
logging.info(f"Đang đẩy ảnh {local_image_path} vào điện thoại...")
# Đẩy ảnh vào thư mục Pictures
remote_path = "/sdcard/Pictures/n8n_fb_comment.jpg"
# Tạo tên file độc nhất để đảm bảo luôn hiện lên ĐẦU thư viện ảnh
random_name = f"n8n_fb_{uuid.uuid4().hex[:8]}.jpg"
remote_path = f"/sdcard/Pictures/{random_name}"
# Xóa bớt các file tạm cũ trước khi đẩy file mới (giữ điện thoại sạch sẽ)
self.d.shell("rm -f /sdcard/Pictures/n8n_fb_*.jpg")
self.d.push(local_image_path, remote_path)
# Gọi Media Scanner để Thư viện ảnh nhận diện ngay lập tức
@@ -111,11 +117,16 @@ class FacebookBot:
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
gallery_images = self.d(className="android.widget.ImageView")
if gallery_images.count >= 2:
gallery_images[1].click() # Bỏ qua icon đầu tiên thường là icon camera
# Facebook gallery mới dùng Button với description 'Ảnh, mục X...'
gallery_images = self.d(descriptionContains="Ảnh, mục")
if not gallery_images.exists:
gallery_images = self.d(descriptionContains="Photo")
if not gallery_images.exists:
gallery_images = self.d(descriptionContains="Ảnh")
if gallery_images.exists:
# Bấm vào ảnh đầu tiên (ảnh vừa mới push vào điện thoại sẽ nằm ở đầu danh sách)
gallery_images[0].click()
time.sleep(1)
self.dump_ui_for_debug("fb_step6_image_selected.xml")