sidestep uv since it suddenly breaks now

This commit is contained in:
lda committed 2026-05-15 00:48:39 +07:00 Verified
1 parent d2140b0c83
commit 4217f77f1a
2 files changed
+9 -5

No files matched your search

+198
View File
@@ -0,0 +1,198 @@
"\
Tool to help with endfield sign-in rewards.\n\n\
It will notify you if you need to log in manually, and then \
wait for you to close the browser after logging in. \n\
If the rewards are claimed successfully, it will notify you as well. \n\
If the rewards have already been claimed, it will let you know.\
"
APP_NAME = "lda's ef sign-in helper"
randomlda = {
APP_NAME: (1) // int("""
.valueOf(), // cool!
};
const fn =
/* """ * 0 + "1")} # fmt: skip
# this is LOVELY
# ruff: noqa: E402
# flake8: noqa: E402
# autopep8: off
import asyncio
import random
import time
from pathlib import Path
from desktop_notifier import DesktopNotifier, Icon
from playwright.async_api import (
Error as PlaywrightError,
)
from playwright.async_api import (
Locator,
Playwright,
async_playwright,
)
from playwright.async_api import (
TimeoutError as PlaywrightTimeoutError,
)
# autopep8: on
CHROME_DATA_DIR = Path(__file__).parent / "chrome-data-dir"
CHROME_DATA_DIR.mkdir(exist_ok=True)
EF_ICON_PATH = Path(__file__).parent / "resources" / "ef_icon.ico"
LOGIN_TIMEOUT_MS = 4 * 60 * 1000
URL = "https://game.skport.com/endfield/sign-in"
async def launch_context(p: Playwright, *, headless: bool):
return await p.chromium.launch_persistent_context(
user_data_dir=CHROME_DATA_DIR,
headless=headless,
)
async def notify(msg: str, title: str = "Login"):
print(f"{title}: {msg}")
notifier = DesktopNotifier(app_name=APP_NAME, app_icon=Icon(EF_ICON_PATH))
# lets see if this blocks
await notifier.send(title=title, message=msg, timeout=5)
# oops this spawns another event loop.
async def needs_manual_login(page):
return await page.locator("form").first.is_visible()
async def already_claimed(container: Locator):
# language=javascript
fn = (
"""
// */
/** @param {HTMLElement} el */
(el) => {
return [...el.parentElement.children].some(
(x) => x !== el && x.id === "completed-overlay" && x.checkVisibility?.(),
);
};
/* *"""
+ "/"
) # yes sir
return await container.evaluate(fn)
async def program():
async with async_playwright() as p:
context = await launch_context(p, headless=True)
page = await context.new_page()
await page.goto(URL)
login_form = page.locator("form").first
container: Locator = page.locator("#lottie-container").first
deadline = time.time() + 60
while time.time() < deadline:
# auth expired
if await login_form.is_visible():
await notify(
"Please log in manually and close the browser. You have 4 minutes.",
title="Manual Login Required",
)
await context.close()
headful = await launch_context(
p,
headless=False,
)
page = headful.pages[0] if headful.pages else await headful.new_page()
await page.goto(URL)
try:
await headful.wait_for_event(
"close",
timeout=LOGIN_TIMEOUT_MS,
)
await notify(
"Browser closed. Please rerun the script.",
title="Browser Closed",
)
except PlaywrightTimeoutError:
await notify(
"Login timeout reached. Please rerun the script.",
title="Login Timeout",
)
try:
await headful.close()
except PlaywrightError:
pass
return
# page not ready yet
if not await container.is_visible():
await page.wait_for_timeout(200)
continue
# already claimed
if (not await login_form.is_visible()) and (
await already_claimed(container)
): # toctou here is crazy
await notify(
"Work already completed elsewhere.",
title="Already Claimed",
)
return
try:
await container.click(
timeout=3000,
delay=random.randint(100, 300),
# we checked for visibility manually. This will probs work.
force=True,
)
await notify(
"Claimed successfully.",
title="Success",
)
return
except (
PlaywrightTimeoutError,
PlaywrightError,
):
pass
await page.wait_for_timeout(1000)
await notify(
"Timed out waiting for claim state.",
title="Timeout",
)
try:
await context.close()
except PlaywrightError:
pass
def main(): # uv no main fix
asyncio.run(program())
if __name__ == "__main__":
main()
# async, also this file is valid js. */ fn;