Compare commits
No commits in common. "2bf04c9e851075920320a0a995a159bafb1c8d0c" and "aebc2ddf89dccee594ea8bb862cb17cd43d266c8" have entirely different histories.
2bf04c9e85
...
aebc2ddf89
@ -1,6 +1,5 @@
|
|||||||
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
|
||||||
@ -82,7 +81,7 @@ class BUCTAU:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def detect_net_requests():
|
def detect_net():
|
||||||
# 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)
|
||||||
@ -92,22 +91,11 @@ 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
|
|
||||||
19
README.md
19
README.md
@ -4,26 +4,11 @@
|
|||||||
|
|
||||||
用crontab理论上也行。
|
用crontab理论上也行。
|
||||||
|
|
||||||
---
|
由于用到了logging。所以service里面要加上`WorkingDirectory=/path/to/programe`。出错先找找权限问题。
|
||||||
|
|
||||||
## 关于登录账号
|
|
||||||
|
|
||||||
在程序的根目录下面新建`.env`文件,里面写
|
|
||||||
```ini
|
|
||||||
BUCT_AUTHENTICATION_USERNAME=你的学号
|
|
||||||
BUCT_AUTHENTICATION_PASSWORD=校园网密码
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 关于service
|
|
||||||
|
|
||||||
由于用到了logging。所以service里面要加上`WorkingDirectory=/path/to/programe`来确保文件可以正常写入 。
|
|
||||||
出错先找找权限问题,我应该是直接给了755。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
现在还是有点问题。比如说没有连接wifi的情况下,request的get会报ssl error然后直接退出。except也不好用。
|
现在还是有点问题。比如说没有连接wifi的情况下,request的get会报ssl error然后直接退出。except也不好用。
|
||||||
我的解决方法就是service里面`Restart=always`,`RestartSec=60`。实测下来是能正常认证的。
|
我的解决方法就是service里面`Restart=always`,`RestartSec=60`。实测下来是能正常认证的。
|
||||||
|
|
||||||
用request来检测纯属闲的,本来还是拿selenium检测的。反正能跑管他呢。
|
用request来检测纯属闲的,本来还是拿selenium检测的。反正能跑管他呢。
|
||||||
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(driver=driver):
|
if authenticator.detect_net():
|
||||||
past_time = time.time()
|
past_time = time.time()
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user