From 89af46c6fce447ba8fab9aab938ab4abdaed57c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 20 Jan 2025 22:01:10 +0100 Subject: [PATCH] Update ohcapi.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A more elegant code to test the internet connection Signed-off-by: Frédéric --- pwnagotchi/plugins/default/ohcapi.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pwnagotchi/plugins/default/ohcapi.py b/pwnagotchi/plugins/default/ohcapi.py index b400c572..5aa6ac5d 100644 --- a/pwnagotchi/plugins/default/ohcapi.py +++ b/pwnagotchi/plugins/default/ohcapi.py @@ -75,20 +75,16 @@ class ohcapi(plugins.Plugin): return # Check if the internet is still available by pinging Google + self.internet_active = False try: response = requests.get('https://www.google.com', timeout=5) + if response.status_code == 200: + self.internet_active = True except requests.ConnectionError: - self.internet_active = False - return - - if response.status_code == 200: - self.internet_active = True - else: - self.internet_active = False return 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.last_run = current_time