Update app/gs_daily.py
Browse files- app/gs_daily.py +25 -10
app/gs_daily.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
# app/gs_daily.py
|
| 2 |
-
|
| 3 |
import asyncio
|
| 4 |
from datetime import datetime
|
| 5 |
from pathlib import Path
|
|
@@ -51,10 +50,8 @@ class GSDailyApp:
|
|
| 51 |
async def run_daily_and_capture(self, cookie_string: str):
|
| 52 |
try:
|
| 53 |
iphone = self.playwright.devices["iPhone 14 Pro"]
|
| 54 |
-
|
| 55 |
context = await self.browser.new_context(**iphone)
|
| 56 |
|
| 57 |
-
# 🔥 Add cookie từ header string
|
| 58 |
cookies = parse_cookie_string(cookie_string)
|
| 59 |
await context.add_cookies(cookies)
|
| 60 |
|
|
@@ -64,19 +61,37 @@ class GSDailyApp:
|
|
| 64 |
await page.wait_for_load_state("networkidle")
|
| 65 |
await page.wait_for_timeout(3000)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
await
|
| 71 |
-
|
| 72 |
-
full_page=True
|
| 73 |
-
)
|
| 74 |
|
| 75 |
await context.close()
|
| 76 |
|
| 77 |
return {
|
| 78 |
"ok": True,
|
| 79 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
}
|
| 81 |
|
| 82 |
except Exception as e:
|
|
|
|
| 1 |
# app/gs_daily.py
|
|
|
|
| 2 |
import asyncio
|
| 3 |
from datetime import datetime
|
| 4 |
from pathlib import Path
|
|
|
|
| 50 |
async def run_daily_and_capture(self, cookie_string: str):
|
| 51 |
try:
|
| 52 |
iphone = self.playwright.devices["iPhone 14 Pro"]
|
|
|
|
| 53 |
context = await self.browser.new_context(**iphone)
|
| 54 |
|
|
|
|
| 55 |
cookies = parse_cookie_string(cookie_string)
|
| 56 |
await context.add_cookies(cookies)
|
| 57 |
|
|
|
|
| 61 |
await page.wait_for_load_state("networkidle")
|
| 62 |
await page.wait_for_timeout(3000)
|
| 63 |
|
| 64 |
+
active_item = page.locator("div[class*='actived']").first
|
| 65 |
+
|
| 66 |
+
if await active_item.count() == 0:
|
| 67 |
+
return {
|
| 68 |
+
"ok": True,
|
| 69 |
+
"claimed": False,
|
| 70 |
+
"message": "Hôm nay đã điểm danh rồi hoặc không tìm thấy ngày hợp lệ"
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
day_text = await active_item.locator("div[class*='item-day']").inner_text()
|
| 74 |
+
|
| 75 |
+
import re
|
| 76 |
+
match = re.search(r"\d+", day_text)
|
| 77 |
+
day_number = int(match.group()) if match else None
|
| 78 |
+
|
| 79 |
+
count_text = await active_item.locator("div[class*='item-cnt']").inner_text()
|
| 80 |
+
|
| 81 |
+
icon_url = await active_item.locator("img").first.get_attribute("src")
|
| 82 |
|
| 83 |
+
await active_item.click()
|
| 84 |
+
await page.wait_for_timeout(2000)
|
|
|
|
|
|
|
| 85 |
|
| 86 |
await context.close()
|
| 87 |
|
| 88 |
return {
|
| 89 |
"ok": True,
|
| 90 |
+
"claimed": True,
|
| 91 |
+
"day": day_number,
|
| 92 |
+
"reward_count": count_text,
|
| 93 |
+
"icon": icon_url,
|
| 94 |
+
"message": f"Đã nhận ngày thứ {day_number}"
|
| 95 |
}
|
| 96 |
|
| 97 |
except Exception as e:
|