def testAll200(self): """return True if site always returns 200 """ r1 = self.get(md5(random.randint())) r2 = self.get(md5(random.randint()) + '/' + md5(random.randint())) if r1.status_code == 200 and r2.status_code == 200: return True return False
def cacheGet(self, path="", cachefile=None): if cachefile is None: cachefile = '.%s.html' % md5(path) if os.path.exists(cachefile): self.logger.debug('cache %s hit' % path) with open(cachefile, 'rb') as fh: return fh.read() else: self.get(path) self.logger.debug('cache save %s to file %s' % (path, cachefile)) with open(cachefile, 'wb') as fh: fh.write(self.lastr.content) return self.lastr.content
def brief(self): if self.lastr is None: return "Exception" msg = "\t".join( map(str, [ self.lastr.status_code, len(self.lastr.content), self.interval, md5(self.lastr.content)[:8] ])) if self.lastr.status_code // 100 == 5: return red(msg) elif self.lastr.status_code // 100 == 4: return cyan(msg) elif self.lastr.status_code // 100 == 3: return green(msg) else: return msg