diff --git a/httptools/__init__.py b/httptools/__init__.py new file mode 100644 index 0000000..6a665ab --- /dev/null +++ b/httptools/__init__.py @@ -0,0 +1,9 @@ +import urllib.request, urllib.error + +def getStatus(url): + try: + return urllib.request.urlopen(url).getcode() + except urllib.error.HTTPError as e: + return e.code + except urllib.error.URLError: + return False diff --git a/siteup.py b/siteup.py new file mode 100755 index 0000000..ae70f1f --- /dev/null +++ b/siteup.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + +import time, setuptools, httptools, twitools + +sites = setuptools.getListSetting("HTTP", "sites") +two = twitools.twObject() + +def check(site, recipient): + status = httptools.getStatus(site) + if not status == 200: + if status == None: + two.tweet("@%s Site %s looks down from here!" % (recipient, site)) + else: + two.tweet("@%s Site %s returns status code %s!" % (recipient, site, status)) + +for s in sites: + check(s[0], s[1])