Skip to content

Instantly share code, notes, and snippets.

@cmc
Last active April 27, 2019 00:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cmc/202b73c247d164cfd99fc2b21cf52207 to your computer and use it in GitHub Desktop.
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