mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
Update ohcapi.py
A more elegant code to test the internet connection Signed-off-by: Frédéric <fmatray@users.noreply.github.com>
This commit is contained in:
@ -75,20 +75,16 @@ class ohcapi(plugins.Plugin):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Check if the internet is still available by pinging Google
|
# Check if the internet is still available by pinging Google
|
||||||
|
self.internet_active = False
|
||||||
try:
|
try:
|
||||||
response = requests.get('https://www.google.com', timeout=5)
|
response = requests.get('https://www.google.com', timeout=5)
|
||||||
|
if response.status_code == 200:
|
||||||
|
self.internet_active = True
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
self.internet_active = False
|
|
||||||
return
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
self.internet_active = True
|
|
||||||
else:
|
|
||||||
self.internet_active = False
|
|
||||||
return
|
return
|
||||||
|
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
if current_time - self.last_run >= self.options['sleep']:
|
if self.internet_active and current_time - self.last_run >= self.options['sleep']:
|
||||||
self._run_tasks(agent)
|
self._run_tasks(agent)
|
||||||
self.last_run = current_time
|
self.last_run = current_time
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user