#!/usr/bin/env python# -*- coding: utf-8 -*-importos# Requires Requests:# http://docs.python-requests.org/en/master/user/install/#distribute-pipimportrequestsfailures=[]endpoints={"steve_adams_me":"http://steve-adams.me","sure":"http://google.ca","nope":"http://fraaaaap.com","nahhh":"http://devinareyoureadingthis.com","wow":"http://imyourgranpappy.com","hoophoop":"http://i<3u.somuch"}# Attempt to get an OK status from each URL.forname,endpointinendpoints.iteritems():try:r=requests.get(endpoint)exceptException:r=Falseifr==Falseorrandr.status_code!=200:failures.append(endpoint)# If any failed, report it using osascript 'display notification'.# This won't work on anything other than OS X Mavericks or better.iflen(failures)>0:msg=""forendpointinfailures:msg+=endpoint+", "msg=msg.replace("http://","")msg=msg.replace("https://","")msg=msg.rstrip(",")os.system("osascript -e 'display notification \""+msg+"\" with title \"These URLs are down:\"'")
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.