Created
December 19, 2012 21:51
-
-
Save samueljackson92/4340862 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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