From 1517ab6084c0907316e04c012cfd839bd2c30790 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Fri, 16 Aug 2019 10:29:25 +1000 Subject: [PATCH] Allow user to log in manually --- spectur_live_view.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/spectur_live_view.py b/spectur_live_view.py index b5e26ee..c0728b8 100644 --- a/spectur_live_view.py +++ b/spectur_live_view.py @@ -18,12 +18,12 @@ from selenium.common.exceptions import (NoSuchElementException, WebDriverException) CAM_ID = 0 -USERNAME = '' -PASSWORD = '' URL = 'https://camera.uwatchit.com.au/UWatchitWebV2/User/LiveView#' OUTPUT_DIR = 'images' TIMEZONE = 'Australia/Sydney' WAIT_TIME = 0.1 +username = '' +password = '' def start_session(): @@ -52,15 +52,25 @@ def login(driver): driver.get(URL) - # Get login fields - usr = driver.find_element_by_id('UserName') - pss = driver.find_element_by_id('Password') - btn = driver.find_element_by_id('submitlogin') - - # Input login details - usr.send_keys(USERNAME) - pss.send_keys(PASSWORD) - btn.click() + # Login automatically if details provided + if username and password: + # Get login fields + usr = driver.find_element_by_id('UserName') + pss = driver.find_element_by_id('Password') + btn = driver.find_element_by_id('submitlogin') + + # Input login details + usr.send_keys(username) + pss.send_keys(password) + btn.click() + else: + # Wait for user to log in manually + while True: + try: + print(driver.find_element_by_id('UserName')) + time.sleep(1) + except NoSuchElementException: + break # Extract cookies session = requests.Session()