Hana Celeste commited on
Commit
9ebaddf
·
verified ·
1 Parent(s): 259a469

Update app/akasa_logic.py

Browse files
Files changed (1) hide show
  1. 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
- async def refresh_akasha(self, uid: str):
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
- # Nếu tab cũ, tải lại trang để đảm bảo nút bấm xuất hiện đúng
51
- await page.goto(url, wait_until="domcontentloaded", timeout=30000)
52
 
53
- # Đợi nút refresh xuất hiện (dựa trên class bạn cung cấp)
54
- # Selector tìm div có class floating-button chứa svg rotate-right
55
- refresh_selector = ".floating-button i.fa-rotate-right, .floating-button svg[data-icon='rotate-right']"
56
 
57
- # Đôi khi Akasha dùng class khác hoặc bọc trong div, ta dùng XPath cho chắc chắn
58
- xpath_selector = "//div[contains(@class, 'floating-button')][.//path[contains(@d, 'M463.5')]]"
59
 
60
- await page.wait_for_selector(xpath_selector, timeout=10000)
 
61
 
62
- # Thực hiện click
63
- await page.click(xpath_selector)
64
 
65
- # Đợi một chút để hệ thống ghi nhận lệnh refresh
 
66
  await asyncio.sleep(2)
67
 
68
  return {
69
  "status": "success",
70
- "message": "Refresh command sent to Akasha",
71
  "uid": uid,
72
  "execution_time": f"{round(time.time() - start_time, 2)}s"
73
  }
74
  except Exception as e:
75
- return {"status": "error", "message": str(e), "uid": uid}
 
 
 
 
 
 
 
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 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():