msg Tweaks
This commit is contained in:
1 file changed
+20
-10
@@ -1,7 +1,8 @@
|
|||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from typing import TYPE_CHECKING, cast
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from playwright.sync_api import (
|
from playwright.sync_api import (
|
||||||
sync_playwright,
|
sync_playwright,
|
||||||
@@ -28,13 +29,15 @@ def launch_context(p, *, headless: bool):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_and_notif(msg: str, title: str = "Endfield Login"):
|
def print_and_notif(msg: str, title: str = "Login"):
|
||||||
print(f"{title}: {msg}")
|
print(f"{title}: {msg}")
|
||||||
|
appname = "lda's ef sign-in helper"
|
||||||
|
# big Windows will disregard the app_name. Format the title instead
|
||||||
|
wintitle = f"{appname}: {title}"
|
||||||
notification.notify(
|
notification.notify(
|
||||||
title=title,
|
title=wintitle if os.name == "nt" else title,
|
||||||
message=msg,
|
message=msg,
|
||||||
app_name="lda's Endfield Login", # this shit doesnt work! always "python"
|
app_name=appname, # big Windows will not care
|
||||||
ticker=msg,
|
ticker=msg,
|
||||||
timeout=5,
|
timeout=5,
|
||||||
)
|
)
|
||||||
@@ -57,6 +60,8 @@ def main():
|
|||||||
if login_form.first.is_visible():
|
if login_form.first.is_visible():
|
||||||
print_and_notif(
|
print_and_notif(
|
||||||
"Please log in manually, then close the browser window."
|
"Please log in manually, then close the browser window."
|
||||||
|
" You have 4 minutes.",
|
||||||
|
title="Manual Login Required",
|
||||||
)
|
)
|
||||||
|
|
||||||
context.close()
|
context.close()
|
||||||
@@ -72,10 +77,13 @@ def main():
|
|||||||
timeout=LOGIN_TIMEOUT_MS,
|
timeout=LOGIN_TIMEOUT_MS,
|
||||||
)
|
)
|
||||||
|
|
||||||
print_and_notif("Browser closed. Please rerun the script.")
|
print_and_notif("Browser closed. Please rerun the script.", title="Browser Closed")
|
||||||
|
|
||||||
except PlaywrightTimeoutError:
|
except PlaywrightTimeoutError:
|
||||||
print_and_notif("Login timeout reached.")
|
print_and_notif(
|
||||||
|
"Login timeout reached. Please rerun the script.",
|
||||||
|
title="Login Timeout",
|
||||||
|
)
|
||||||
headful.close()
|
headful.close()
|
||||||
|
|
||||||
break
|
break
|
||||||
@@ -88,7 +96,7 @@ def main():
|
|||||||
delay=random.randint(100, 300),
|
delay=random.randint(100, 300),
|
||||||
)
|
)
|
||||||
|
|
||||||
print_and_notif("Login successful.")
|
print_and_notif("Claimed successfully.", title="Success")
|
||||||
break
|
break
|
||||||
|
|
||||||
except (PlaywrightTimeoutError, PlaywrightError) as e:
|
except (PlaywrightTimeoutError, PlaywrightError) as e:
|
||||||
@@ -98,7 +106,9 @@ def main():
|
|||||||
"intercepts pointer events" in msg
|
"intercepts pointer events" in msg
|
||||||
and "completed-overlay" in msg
|
and "completed-overlay" in msg
|
||||||
):
|
):
|
||||||
print_and_notif("Work already completed elsewhere.")
|
print_and_notif(
|
||||||
|
"Work already completed elsewhere.", title="Already Claimed"
|
||||||
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
raise # re-raise other exceptions
|
raise # re-raise other exceptions
|
||||||
@@ -107,7 +117,7 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
context.close()
|
context.close()
|
||||||
except:
|
except PlaywrightError: # ignore if already closed
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user