Hana Celeste commited on
Update app/akasa_logic.py
Browse files- app/akasa_logic.py +22 -15
app/akasa_logic.py
CHANGED
|
@@ -40,39 +40,46 @@ class AkasaApp:
|
|
| 40 |
self.cache[uid] = {"page": page, "context": context, "expires": time.time() + 180}
|
| 41 |
return page, True
|
| 42 |
|
| 43 |
-
|
| 44 |
-
"""Logic chính: Truy cập akasha.cv và nhấn nút Refresh"""
|
| 45 |
start_time = time.time()
|
| 46 |
page, is_new = await self.get_page(uid)
|
| 47 |
url = f"https://akasha.cv/profile/{uid}"
|
| 48 |
|
| 49 |
try:
|
| 50 |
-
#
|
| 51 |
-
await page.goto(url, wait_until="
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
refresh_selector = ".floating-button i.fa-rotate-right, .floating-button svg[data-icon='rotate-right']"
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
await page.click(
|
| 64 |
|
| 65 |
-
#
|
|
|
|
| 66 |
await asyncio.sleep(2)
|
| 67 |
|
| 68 |
return {
|
| 69 |
"status": "success",
|
| 70 |
-
"message": "Refresh command
|
| 71 |
"uid": uid,
|
| 72 |
"execution_time": f"{round(time.time() - start_time, 2)}s"
|
| 73 |
}
|
| 74 |
except Exception as e:
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
async def stop(self):
|
| 78 |
for item in self.cache.values():
|
|
|
|
| 40 |
self.cache[uid] = {"page": page, "context": context, "expires": time.time() + 180}
|
| 41 |
return page, True
|
| 42 |
|
| 43 |
+
async def refresh_akasha(self, uid: str):
|
|
|
|
| 44 |
start_time = time.time()
|
| 45 |
page, is_new = await self.get_page(uid)
|
| 46 |
url = f"https://akasha.cv/profile/{uid}"
|
| 47 |
|
| 48 |
try:
|
| 49 |
+
# Tăng timeout lên 45s cho lần load đầu
|
| 50 |
+
await page.goto(url, wait_until="networkidle", timeout=45000)
|
| 51 |
|
| 52 |
+
# Selector dựa trên thuộc tính title bạn đã gửi
|
| 53 |
+
refresh_btn_selector = 'div[title="Refresh builds"]'
|
|
|
|
| 54 |
|
| 55 |
+
# Đợi nút xuất hiện
|
| 56 |
+
await page.wait_for_selector(refresh_btn_selector, state="visible", timeout=15000)
|
| 57 |
|
| 58 |
+
# Cuộn đến nút để chắc chắn nó click được
|
| 59 |
+
await page.locator(refresh_btn_selector).scroll_into_view_if_needed()
|
| 60 |
|
| 61 |
+
# Click vào nút
|
| 62 |
+
await page.click(refresh_btn_selector)
|
| 63 |
|
| 64 |
+
# Kiểm tra xem sau khi click có hiện thông báo "Last profile update" đang thay đổi không
|
| 65 |
+
# Đây là bước phụ để xác nhận lệnh đã chạy
|
| 66 |
await asyncio.sleep(2)
|
| 67 |
|
| 68 |
return {
|
| 69 |
"status": "success",
|
| 70 |
+
"message": "Refresh command executed",
|
| 71 |
"uid": uid,
|
| 72 |
"execution_time": f"{round(time.time() - start_time, 2)}s"
|
| 73 |
}
|
| 74 |
except Exception as e:
|
| 75 |
+
# Chụp ảnh màn hình lỗi để debug (tùy chọn, lưu trên HuggingFace)
|
| 76 |
+
# await page.screenshot(path="error_akasha.png")
|
| 77 |
+
return {
|
| 78 |
+
"status": "error",
|
| 79 |
+
"message": "Nút Refresh không tìm thấy hoặc trang load quá chậm.",
|
| 80 |
+
"detail": str(e),
|
| 81 |
+
"uid": uid
|
| 82 |
+
}
|
| 83 |
|
| 84 |
async def stop(self):
|
| 85 |
for item in self.cache.values():
|