Implement URL checker
This commit is contained in:
parent
a2b6d3d2e0
commit
4a6dc4417b
9
httptools/__init__.py
Normal file
9
httptools/__init__.py
Normal file
|
@ -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
|
17
siteup.py
Executable file
17
siteup.py
Executable file
|
@ -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])
|
Loading…
Reference in a new issue