Adjust timeouts, use ping's return value
This commit is contained in:
parent
f803075932
commit
7b6f5afc2c
13
thaiwifi.py
13
thaiwifi.py
|
@ -15,21 +15,24 @@ PING_COMMAND = 'ping -c {} -W {} -i {} {} > /dev/null 2>&1'
|
||||||
|
|
||||||
LOGIN_URL = 'http://login.tulip.biz/portal/user-authen.php'
|
LOGIN_URL = 'http://login.tulip.biz/portal/user-authen.php'
|
||||||
LOGIN = dict(txtLogin='tb215', txtPasswd='363499')
|
LOGIN = dict(txtLogin='tb215', txtPasswd='363499')
|
||||||
LOGIN_TIMEOUT = 10
|
LOGIN_TIMEOUT = 20
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
connected = not os.system(PING_COMMAND.format(COUNT, TIMEOUT, INTERVAL, HOST))
|
ret = os.system(PING_COMMAND.format(COUNT, TIMEOUT, INTERVAL, HOST))
|
||||||
|
|
||||||
if not connected:
|
if ret == 2:
|
||||||
|
break
|
||||||
|
elif ret == 256:
|
||||||
requests.post(LOGIN_URL, data=LOGIN, timeout=LOGIN_TIMEOUT)
|
requests.post(LOGIN_URL, data=LOGIN, timeout=LOGIN_TIMEOUT)
|
||||||
logging.info('Attempted to login.')
|
logging.info('Attempted to login.')
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
time.sleep(0.5)
|
time.sleep(5)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logging.info('Exiting...')
|
|
||||||
break
|
break
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
logging.error(str(e))
|
logging.error(str(e))
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
logging.info('Exiting...')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user