Update app/gs_daily.py
Browse files- app/gs_daily.py +30 -13
app/gs_daily.py
CHANGED
|
@@ -47,19 +47,38 @@ class GSDailyApp:
|
|
| 47 |
if self.playwright:
|
| 48 |
await self.playwright.stop()
|
| 49 |
|
| 50 |
-
async def run_daily_and_capture(self, cookie_string: str):
|
| 51 |
try:
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
cookies = parse_cookie_string(cookie_string)
|
| 56 |
await context.add_cookies(cookies)
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
await page.goto(CHECKIN_URL, timeout=60000, wait_until="domcontentloaded")
|
| 61 |
await page.wait_for_load_state("networkidle")
|
| 62 |
-
await page.wait_for_timeout(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
active_item = page.locator("div[class*='actived']").first
|
| 65 |
|
|
@@ -67,7 +86,7 @@ class GSDailyApp:
|
|
| 67 |
return {
|
| 68 |
"ok": True,
|
| 69 |
"claimed": False,
|
| 70 |
-
"message": "Hôm nay đã điểm danh rồi
|
| 71 |
}
|
| 72 |
|
| 73 |
day_text = await active_item.locator("div[class*='item-day']").inner_text()
|
|
@@ -77,21 +96,19 @@ class GSDailyApp:
|
|
| 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 |
-
|
| 94 |
-
|
|
|
|
| 95 |
}
|
| 96 |
|
| 97 |
except Exception as e:
|
|
|
|
| 47 |
if self.playwright:
|
| 48 |
await self.playwright.stop()
|
| 49 |
|
| 50 |
+
async def run_daily_and_capture(self, cookie_string: str, discord_id: str):
|
| 51 |
try:
|
| 52 |
+
if discord_id not in self.sessions:
|
| 53 |
+
iphone = self.playwright.devices["iPhone 14 Pro"]
|
| 54 |
|
| 55 |
+
context = await self.browser.new_context(**iphone)
|
| 56 |
+
page = await context.new_page()
|
| 57 |
+
|
| 58 |
+
self.sessions[discord_id] = {
|
| 59 |
+
"context": context,
|
| 60 |
+
"page": page
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
session = self.sessions[discord_id]
|
| 64 |
+
page = session["page"]
|
| 65 |
+
context = session["context"]
|
| 66 |
+
|
| 67 |
+
await context.clear_cookies()
|
| 68 |
cookies = parse_cookie_string(cookie_string)
|
| 69 |
await context.add_cookies(cookies)
|
| 70 |
|
| 71 |
+
await page.goto(CHECKIN_URL, wait_until="domcontentloaded")
|
|
|
|
|
|
|
| 72 |
await page.wait_for_load_state("networkidle")
|
| 73 |
+
await page.wait_for_timeout(2000)
|
| 74 |
+
|
| 75 |
+
login_button = page.locator("span:has-text('Đăng Nhập')")
|
| 76 |
+
|
| 77 |
+
if await login_button.count() > 0:
|
| 78 |
+
return {
|
| 79 |
+
"ok": False,
|
| 80 |
+
"error": "Cookie không hợp lệ hoặc đã hết hạn"
|
| 81 |
+
}
|
| 82 |
|
| 83 |
active_item = page.locator("div[class*='actived']").first
|
| 84 |
|
|
|
|
| 86 |
return {
|
| 87 |
"ok": True,
|
| 88 |
"claimed": False,
|
| 89 |
+
"message": "Hôm nay đã điểm danh rồi"
|
| 90 |
}
|
| 91 |
|
| 92 |
day_text = await active_item.locator("div[class*='item-day']").inner_text()
|
|
|
|
| 96 |
day_number = int(match.group()) if match else None
|
| 97 |
|
| 98 |
count_text = await active_item.locator("div[class*='item-cnt']").inner_text()
|
|
|
|
| 99 |
icon_url = await active_item.locator("img").first.get_attribute("src")
|
| 100 |
|
| 101 |
await active_item.click()
|
| 102 |
await page.wait_for_timeout(2000)
|
| 103 |
|
|
|
|
|
|
|
| 104 |
return {
|
| 105 |
"ok": True,
|
| 106 |
"claimed": True,
|
| 107 |
"day": day_number,
|
| 108 |
"reward_count": count_text,
|
| 109 |
+
"icon": icon_url,
|
| 110 |
+
"discord_id": discord_id,
|
| 111 |
+
"message": f"Đã nhận ngày thứ {day_number}"
|
| 112 |
}
|
| 113 |
|
| 114 |
except Exception as e:
|