Skip to content

Instantly share code, notes, and snippets.

@samueljackson92
Created December 19, 2012 21:51
Show Gist options
  • Save samueljackson92/4340862 to your computer and use it in GitHub Desktop.
Save samueljackson92/4340862 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from json import load
from urllib2 import urlopen, URLError
from argparse import ArgumentParser
def printError(e):
print "Error connecting to API: "
print "\t", e
def getLinks():
try:
#get API urls
return load(urlopen("https://status.github.com/api.json"))
except URLError, e:
printError(e)
def getStatus():
try:
#get the last message on the API and print it
response = load(urlopen(LINKS['last_message_url']))
print "GitHub responded with the following message:"
print "Status: " + response['status'].upper()
print "Last update: ", response['created_on']
print "Message: ", response['body']
except URLError, e:
printError(e)
if __name__ == '__main__':
#parse command line options
parser = ArgumentParser(description="Check the GitHub status API")
parser.add_argument('status', help='Check the status of GitHub')
args = parser.parse_args()
print "Connecting to GitHub Status API..."
LINKS = getLinks()
if args.status:
getStatus()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment