Score:1

Indicator to show online / offline in 22.04

us flag

I have this Python code that sends a notification when we are offline. I was wondering whether it is possible to have a visible indicator based on this code in Ubuntu 22.04. Green when the connection is ON and Red when it is OFF.

This code is half mine and half from tutorials on the internet

# importing required modules
import http.client as httplib
import os
import time

   
i = 1

while i < 10:  
   


    def connection_check(url="www.google.com", timeout=3):
        connection = httplib.HTTPConnection(url, timeout=timeout)

        try:
            connection.request("HEAD", "/")
            connection.close()
            print("Active Connection")
            return True
        except Exception as exep:
            os.system('notify-send  "You are offline !!" --icon="/home/myname/PycharmProjects/net_status/cry.png"')
            print(exep)
            return False

    connection_check("www.google.com", 3)
    
    # wait for 1 minute before the next check

    time.sleep(60)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.