Ejemplo n.º 1
0
def kruskal(graph):
    """
    Apply Kruskal algorithm to find minimum spanning tree of a graph

    :param graph: A list of nodes (a graph)
    :return: Spanning tree of a graph as a list of nodes (a graph)
    """

    edges = sort_edge(graph)
    graph = deepcopy(graph)
    for e in edges:
        s, d, w = e

        des_node = [n for n in graph if n.idx == d][0]
        for n in graph:
            if n.idx == s:
                n.remove_adjacent(d)
                print(s, '->', d, ':', w, ' Removed!')
                break
        if not is_connected(graph):
            for n in graph:
                if n.idx == s:
                    n.add_adjacent(des_node, w)
                    print(s, '->', d, ':', w, ' Added!')

    return graph
    def load_page_by_url(self, full_url, sleep_time=10):
        count_retry = 1

        try:
            while not utils.is_connected():
                if count_retry in range(6):
                    log.warn("NO INTERNET, Short retry [{0}/5], Next try -> {1} sec".format(count_retry, sleep_time))
                    time.sleep(sleep_time)
                elif count_retry in range(11):
                    long_sleep_time = sleep_time * 180
                    log.warn(
                        "NO INTERNET, Long retry [{0}/5], Next try -> {1} sec".format(count_retry - 5, long_sleep_time))
                    time.sleep(long_sleep_time)
                elif count_retry > 10:
                    log.critical("OOPS!! Error. Make sure you are connected to Internet and restart script.")
                    sys.exit(0)
                count_retry = count_retry + 1

            return self.session.get(full_url, allow_redirects=True, timeout=20, headers={'User-Agent': self.user_agent})

        except requests.ConnectionError as e:
            log.warn(e)
            return
        except requests.Timeout as e:
            log.warn(e)
            return self.load_page_by_url(full_url)
Ejemplo n.º 3
0
 def connected(self):
     """
     Prompt when disconnected
     """
     if is_connected():
         return True
     self.log('Connection lost!', 'red')
     QMessageBox.critical(self, 'elmoCut', 'Connection Lost!')
     return False
Ejemplo n.º 4
0
async def internet_pooling(function, interval, kwargs):
    max_sleep = 15 * 60
    sleep_if_no_internet = interval

    while 1:
        logging.debug(f"Run function {function.__name__}")
        if is_connected():
            sleep_if_no_internet = interval
            await function(**kwargs)
            await sleep(interval)
        else:
            logging.error(
                f'No internet connection. sleep for {sleep_if_no_internet} seconds'
            )
            await sleep(min(sleep_if_no_internet, max_sleep))
            sleep_if_no_internet += interval
Ejemplo n.º 5
0
if not os.path.exists(DATA_PATH):
    os.makedirs(DATA_PATH)
if not os.path.exists(BACKUP_RECORDS_PATH):
    os.makedirs(BACKUP_RECORDS_PATH)

darkicePidPath = DATA_PATH + 'darkice.pid'
darkiceMd5Path = DATA_PATH + 'darkice.md5'

with open(darkiceMd5Path, 'r') as f:
    if f.read() != utils.fileMd5(DARKICE_CFG_PATH):
        utils.killDarkice(RECORD_PATH, BACKUP_RECORDS_PATH)

leds = LedHandler()

if not utils.is_connected(STREAMING_URL):
    print 'estado 1 - sin internet'
    leds.noInternet()
    exit()

if not utils.has_soundcard():
    print 'estado 2 - sin sonido'
    leds.noSoundCard()
    exit()

if not utils.has_streaming_connection(darkicePidPath):
    utils.killDarkice(RECORD_PATH, BACKUP_RECORDS_PATH)
    utils.textToFile(utils.fileMd5(DARKICE_CFG_PATH), darkiceMd5Path)
    darkiceProcess = subprocess.Popen(['darkice', '-c', DARKICE_CFG_PATH])
    print 'running darkice with pid ' + str(darkiceProcess.pid)
    utils.textToFile(darkiceProcess.pid, darkicePidPath)
Ejemplo n.º 6
0
import os
from time import sleep
from utils import is_connected, get_ip, get_ssid
from config import CONN_CHECK_INTERVAL
import logger
import sender

sleep(20)  # Prevents script from starting immediately
logger.log("Watcher started")

interval = CONN_CHECK_INTERVAL
connected = is_connected()

last_known_ssid = ""

if interval < 30:
    interval = 30

if connected:
    # SEND EMAIL ON BOOT
    ip = str(get_ip())
    ssid = str(get_ssid())
    last_known_ssid = ssid
    sender.send_mail("RaspIP", ssid + ": " + ip)
    logger.log("Email sent on boot with following data: " + ssid + ", " + ip)

while True:
    connected = is_connected()
    print("Connected: " + str(connected))
    if not connected:
        logger.log("Watcher triggering reconnect")
Ejemplo n.º 7
0
from time import sleep
from utils import get_ssid, get_ip, is_connected
import os
import logger
import sender


def reconnect():
    connectCmd = "wpa_cli -i wlan0 reconfigure &"
    logger.log("Reconnecting...")
    os.system(connectCmd)


if is_connected():
    ip = str(get_ip())
    ssid = str(get_ssid())
    sender.send_mail("RaspIP", ssid + ": " + ip)
else:
    reconnect()