Skip to content

Instantly share code, notes, and snippets.

@sidwarkd
Forked from eduardkoller/isgovtdown.py
Last active December 24, 2015 14:39
Show Gist options
  • Save sidwarkd/6814331 to your computer and use it in GitHub Desktop.
Save sidwarkd/6814331 to your computer and use it in GitHub Desktop.
Modified to add command line option for running on a Raspberry Pi using GPIO 17 and 18 to control status LEDs. Run from the command line with the argument "pi" to activate status LEDs. Assumes you have already installed the RPi.GPIO library.
#!/usr/bin/env python
#
# file: isgovtdown.py
#
# description: checks usa.gov for the "Government has shut down" message
#
# usage: ./isgovtdown.py [pi]
# Passing argument 'pi' causes status LEDs to be used
#
# or in a crontab:
# */5 * * * * /path/to/isgovtdown.py && mailx -s 5s [email protected]
#
import re, sys, urllib
from time import sleep
import RPi.GPIO as GPIO
mode = 0;
if(len(sys.argv) > 1):
argMode = sys.argv[1].lower()
if(argMode == "pi"):
mode = 1
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11, True)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, True)
print("Press Ctrl-C to cancel monitoring and admit you don't care")
print("")
try:
while True:
if(mode == 0):
sys.stdout.write('Checking.....')
sys.stdout.flush()
else:
GPIO.output(11, True)
GPIO.output(12, True)
# Add a delay for effect
sleep(3)
page = urllib.urlopen("http://usa.gov").read()
if(re.search(b'Due to a lapse in funding, the U.S. federal government has shut down',page)):
if(mode == 0):
print("Government still down")
else:
GPIO.output(11, True)
GPIO.output(12, False)
else:
if(mode == 0):
print ("Government back up")
else:
GPIO.output(12, True)
GPIO.output(11, False)
sleep(60)
except KeyboardInterrupt:
if(mode == 1):
GPIO.output(11, True)
GPIO.output(12, True)
GPIO.cleanup()
sys.exit(1)
@sidwarkd
Copy link
Author

sidwarkd commented Oct 3, 2013

If you find this please be gentle on the code criticism. This is the first time I've written in Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment