Created
April 25, 2018 22:29
-
-
Save andkon/dac8e4eece8b08a9549079e81433c2dc to your computer and use it in GitHub Desktop.
Site Status Blink1 Script
This file contains hidden or 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
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