Fix build: Bundle schwab_scraper source and use local dependencies
All checks were successful
Build and Push Docker Image / build (push) Successful in 34s
All checks were successful
Build and Push Docker Image / build (push) Successful in 34s
This commit is contained in:
38
schwab_scraper/browser/navigation.py
Normal file
38
schwab_scraper/browser/navigation.py
Normal file
@@ -0,0 +1,38 @@
|
||||
async def ensure_authenticated_page(page, context, debug: bool = False) -> bool:
|
||||
if 'login' in page.url.lower() or 'sessiontimeout=y' in page.url.lower():
|
||||
if debug:
|
||||
print("DEBUG: Detected session timeout, attempting re-authentication...")
|
||||
from ..core.config import load_config, get_schwab_credentials # adjusted after refactor
|
||||
from .auth import login_to_schwab
|
||||
config = load_config()
|
||||
username, password = get_schwab_credentials(config)
|
||||
if username and password:
|
||||
fresh_cookies = await login_to_schwab(username, password)
|
||||
if fresh_cookies:
|
||||
await context.clear_cookies()
|
||||
await context.add_cookies(fresh_cookies)
|
||||
if debug:
|
||||
print("DEBUG: Re-authentication successful")
|
||||
return True
|
||||
else:
|
||||
if debug:
|
||||
print("DEBUG: Re-authentication failed")
|
||||
return False
|
||||
else:
|
||||
if debug:
|
||||
print("DEBUG: No credentials available for re-authentication")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
async def goto_with_auth_check(page, context, url: str, debug: bool = False, timeout: int = 60000):
|
||||
await page.goto(url, timeout=timeout)
|
||||
await page.wait_for_load_state('domcontentloaded')
|
||||
if not await ensure_authenticated_page(page, context, debug=debug):
|
||||
return False
|
||||
if 'login' in page.url.lower() or 'sessiontimeout=y' in page.url.lower():
|
||||
await page.goto(url, timeout=timeout)
|
||||
await page.wait_for_load_state('domcontentloaded')
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user