def network_is_available():
    """
    Check whether the network is available.
    :return: whether the network is available.
    :rtype: bool
    """
    # to be sure, test multiple sites in case one of them is offline
    test_sites = [
        "https://github.com/ywangd/stash/",  # main StaSh repo
        "https://forum.omz-software.com/",  # pythonista forums
        "https://python.org/",  # python website
        ]
    for url in test_sites:
        try:
            requests.get(url, timeout=5.0)
        except (requests.ConnectionError, requests.Timeout):
            # can not connect, retry.
            continue
        else:
            # successfully connected.
            return True
    return False

    Check whether the network is available.
    :return: whether the network is available.
    :rtype: bool
    
tests/stashtest.py