Skip to content

Instantly share code, notes, and snippets.

@andkon
Created April 25, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andkon/dac8e4eece8b08a9549079e81433c2dc to your computer and use it in GitHub Desktop.
Save andkon/dac8e4eece8b08a9549079e81433c2dc to your computer and use it in GitHub Desktop.
Site Status Blink1 Script
from blink1.blink1 import Blink1
import requests
import time
"""
I run this with a bash script, `something.sh`, which just runs it, and which will catch any errors that it can then email to me:
python3.6 statusblinker.py
"""
b1 = Blink1()
b1.fade_to_color(100,'blue')
sites = ("http://anysiteyouwant.com",
"http://coolsites.co"
)
try:
r = requests.get("https://google.com")
r.raise_for_status()
except:
print("%s: Deskpi can't reach google or the internet." % (time.strftime('%x %X(%Z)')))
exit()
all_good = None
for site in sites:
r = requests.get(site)
if not r:
all_good = False
print("%s: %s is offline" % (time.strftime('%x %X(%Z)'),r.url))
break
else:
all_good=True
if all_good==False:
b1.fade_to_color(100,'red')
else:
b1.fade_to_color(100, 'green')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment