Skip to content

Instantly share code, notes, and snippets.

@owainlewis
Created July 31, 2012 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owainlewis/3218254 to your computer and use it in GitHub Desktop.
Save owainlewis/3218254 to your computer and use it in GitHub Desktop.
Dirty QA
import urllib2, urlparse
# Check a text file of urls to make sure they return a status 200
class StatusChecker(object):
""" Check the status codes of multiple URLS """
def __init__(self, url_file="urls.txt"):
self.url_file = url_file
self.urls = [line.strip() for line in open(self.url_file)]
self.url_map = map((lambda x: self.format_url(x)), self.urls)
def format_url(self, url):
if not url.startswith('http'):
url = '%s%s' % ('http://', url)
return url
def get_status_code(self, url):
try:
result = None
connection = urllib2.urlopen(url)
result = connection.getcode()
connection.close()
return result
except urllib2.HTTPError, e:
return e.code
def check_all(self):
for url in self.url_map:
code = self.get_status_code(url)
print "%s : %s" % (code, url)
def main():
StatusChecker().check_all()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment