feat: implement FastAPI service with structured logging and automated script modification utility

This commit is contained in:
Victor Phan
2026-07-21 10:16:15 +07:00
parent adbfb43a48
commit 0c587685a5
3 changed files with 34 additions and 10 deletions
+11 -10
View File
@@ -1,12 +1,13 @@
import logging
import uiautomator2 as u2
import time
import re
class ShopeeBot:
def __init__(self, device_ip: str):
print(f"Đang kết nối tới thiết bị {device_ip}...")
logging.info(f"Đang kết nối tới thiết bị {device_ip}...")
self.d = u2.connect(device_ip)
print("Kết nối thành công!")
logging.info("Kết nối thành công!")
def get_commission_rate(self, url: str) -> str:
try:
@@ -14,7 +15,7 @@ class ShopeeBot:
self.d.screen_on()
# 2. Khởi động lại Shopee từ đầu để tránh lỗi luồng cũ
print("Khởi động Shopee...")
logging.info("Khởi động Shopee...")
self.d.app_start("com.shopee.vn", stop=True)
time.sleep(6) # Chờ app khởi động hoàn toàn
@@ -24,7 +25,7 @@ class ShopeeBot:
time.sleep(1)
# 3. Chuyển sang tab "Tôi"
print("Vào tab Tôi...")
logging.info("Vào tab Tôi...")
if self.d(text="Tôi").exists:
self.d(text="Tôi").click()
else:
@@ -32,7 +33,7 @@ class ShopeeBot:
time.sleep(2)
# 4. Tìm và ấn "Shopee Tiếp Thị Liên Kết"
print("Tìm mục Shopee Tiếp Thị Liên Kết...")
logging.info("Tìm mục Shopee Tiếp Thị Liên Kết...")
# Cuộn xuống cho đến khi thấy chữ này
self.d(scrollable=True).scroll.to(textContains="Tiếp Thị Liên Kết")
@@ -44,7 +45,7 @@ class ShopeeBot:
time.sleep(6) # Mục này có thể tải hơi lâu vì gọi API
# 5. Ấn tab "Tài khoản" ở thanh menu dưới cùng của Affiliate
print("Vào tab Tài khoản...")
logging.info("Vào tab Tài khoản...")
if self.d(text="Tài khoản").exists:
self.d(text="Tài khoản").click()
else:
@@ -52,7 +53,7 @@ class ShopeeBot:
time.sleep(2)
# 5.1. Bấm vào "Chuyển đổi liên kết" trong danh sách
print("Bấm vào mục Chuyển đổi liên kết...")
logging.info("Bấm vào mục Chuyển đổi liên kết...")
if self.d(text="Chuyển đổi liên kết").exists:
self.d(text="Chuyển đổi liên kết").click()
else:
@@ -60,7 +61,7 @@ class ShopeeBot:
time.sleep(2)
# 6. Nhập link vào ô Text
print("Nhập link sản phẩm...")
logging.info("Nhập link sản phẩm...")
# Nếu có nút "Xóa tất cả" link cũ thì xóa trước
if self.d(text="Xóa tất cả").exists:
self.d(text="Xóa tất cả").click()
@@ -75,7 +76,7 @@ class ShopeeBot:
time.sleep(1)
# 7. Bấm nút Chuyển Đổi màu cam
print("Bấm nút Chuyển Đổi...")
logging.info("Bấm nút Chuyển Đổi...")
if self.d(text="Chuyển Đổi").exists:
self.d(text="Chuyển Đổi").click()
else:
@@ -84,7 +85,7 @@ class ShopeeBot:
time.sleep(4) # Chờ Shopee convert link và hiện kết quả
# 8. Lấy tỷ lệ hoa hồng, link mới và giá
print("Đang đọc kết quả trên màn hình...")
logging.info("Đang đọc kết quả trên màn hình...")
import json
import re