Last active
April 27, 2019 00:39
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os | |
import requests | |
import sys | |
import time | |
ROOT = logging.getLogger() | |
ROOT.setLevel(logging.DEBUG) | |
HANDLER = logging.StreamHandler(sys.stdout) | |
HANDLER.setLevel(logging.DEBUG) | |
FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
HANDLER.setFormatter(FORMATTER) | |
ROOT.addHandler(HANDLER) | |
inet_yes = 0 | |
inet_count = 0 | |
inet_active = False | |
while True: | |
r = requests.get('https://www.unitedwifi.com/portal/l/index') | |
inet_count += 1 | |
if r.ok: | |
if "DISCONNECTED" not in r.text: | |
logging.debug("Internet is YES!") | |
if not inet_active: | |
os.system("/usr/bin/osascript -e 'display dialog \"The Internet hath returned.\" buttons {\"OK\"} default button 1'") | |
inet_yes += 1 | |
inet_active = True | |
else: | |
logging.debug("Internet is NO...") | |
logging.debug("sleeping for 5s..") | |
inet_active = False | |
if inet_yes == 0: | |
uptime = 0 | |
else: | |
uptime = (inet_yes / inet_count * 100) | |
logging.debug("internet uptime: %{} ({} checks, {} successes)".format(uptime, inet_count, inet_yes)) | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment