Complement the README file.
This commit is contained in:
parent
e0cf820637
commit
10391fd746
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import time
|
||||||
import selenium.common.exceptions
|
import selenium.common.exceptions
|
||||||
import urllib3
|
import urllib3
|
||||||
import logging
|
import logging
|
||||||
@ -81,7 +82,7 @@ class BUCTAU:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def detect_net():
|
def detect_net_requests():
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
detector = requests.get(url="https://www.baidu.com", timeout=5)
|
detector = requests.get(url="https://www.baidu.com", timeout=5)
|
||||||
@ -91,11 +92,22 @@ class BUCTAU:
|
|||||||
else:
|
else:
|
||||||
logging.info("Network is not available")
|
logging.info("Network is not available")
|
||||||
return False
|
return False
|
||||||
except urllib3.exceptions.MaxRetryError:
|
|
||||||
logging.info("MaxRetryError: False")
|
|
||||||
return False
|
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logging.info("ConnectionError: False")
|
logging.info("ConnectionError: False")
|
||||||
return False
|
return False
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def detect_net(driver):
|
||||||
|
# noinspection PyBroadException
|
||||||
|
try:
|
||||||
|
driver.get("https://tree.buct.edu.cn/index_20.html")
|
||||||
|
driver.maximize_window()
|
||||||
|
time.sleep(3) # Wait for the page to load
|
||||||
|
driver.find_element(By.XPATH, '/html/body/main/section/div[1]/div[7]/button[1]')
|
||||||
|
logging.info("Have logged in")
|
||||||
|
return True # Not logged in
|
||||||
|
except Exception:
|
||||||
|
logging.warning("Not logged in")
|
||||||
|
return False
|
||||||
|
2
run.py
2
run.py
@ -9,7 +9,7 @@ def main():
|
|||||||
past_time = time.time()
|
past_time = time.time()
|
||||||
while True:
|
while True:
|
||||||
if time.time() - past_time > 10.0:
|
if time.time() - past_time > 10.0:
|
||||||
if authenticator.detect_net():
|
if authenticator.detect_net(driver=driver):
|
||||||
past_time = time.time()
|
past_time = time.time()
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user