libs/webtracker.py
def status(self):
        """
        A generator to return status for all URLs at the specific period
        :return: A generator yielding WebsiteStatus objects
        """
        for url, re_exp in self._urls.items():
            status = 'unresponsive'
            dns_time = None
            response_time = None
            detail = None

            # We can resolve domain one-off in __init__ but decided not to do so
            # since this is not a time-critical task and it is handy to do in this way.
            domain = urlparse(url).netloc
            try:
                # Measure DNS query time firstly
                stime = time.time()
                # We are measuring DNS response in a rough way through dns.resolver module
                dns.resolver.resolve(domain, 'A')
                etime = time.time()
                # DNS response time in ms
                dns_time = int((etime - stime) * 1000)
                stime = time.time()
                r = requests.get(url, timeout=self.timeout)
                r.close()
                etime = time.time()
                # Total Response time in ms
                response_time = int((etime - stime) * 1000)
                status = 'responsive'
                phrase = self.status_mapping[r.status_code]
                if re_exp:
                    if not re_exp.findall(r.text):
                        phrase = 'Page content not expected'
                        detail = f'{self.urls[url]}'
            except dns.resolver.NXDOMAIN:
                phrase = 'domain not exist'
            except requests.exceptions.SSLError:
                status = 'responsive'
                phrase = 'ssl error'
            except requests.exceptions.ConnectTimeout:
                phrase = 'connection timeout'
            except Exception as e:  # This should never happen, but just in case.
                phrase = str(e).lower()
            yield WebsiteStatus(self.track_from, url, status, phrase, dns_time, response_time, detail)

        A generator to return status for all URLs at the specific period
        :return: A generator yielding WebsiteStatus objects
        
A generator to return status for all URLs at the specific period
A generator to return status for all URLs at the specific period
def status(self):
        for url, re_exp in self._urls.items():
            status = 'unresponsive'
            dns_time = None
            response_time = None
            detail = None
            domain = urlparse(url).netloc
            try:
                stime = time.time()
                dns.resolver.resolve(domain, 'A')
                etime = time.time()
                dns_time = int((etime - stime) * 1000)
                stime = time.time()
                r = requests.get(url, timeout=self.timeout)
                r.close()
                etime = time.time()
                response_time = int((etime - stime) * 1000)
                status = 'responsive'
                phrase = self.status_mapping[r.status_code]
                if re_exp:
                    if not re_exp.findall(r.text):
                        phrase = 'Page content not expected'
                        detail = f'{self.urls[url]}'
            except dns.resolver.NXDOMAIN:
                phrase = 'domain not exist'
            except requests.exceptions.SSLError:
                status = 'responsive'
                phrase = 'ssl error'
            except requests.exceptions.ConnectTimeout:
                phrase = 'connection timeout'
            except Exception as e:  
                phrase = str(e).lower()
            yield WebsiteStatus(self.track_from, url, status, phrase, dns_time, response_time, detail)
def status ( self ) : for url , re_exp in self . _urls . items ( ) : status = 'unresponsive' dns_time = None response_time = None detail = None domain = urlparse ( url ) . netloc try : stime = time . time ( ) dns . resolver . resolve ( domain , 'A' ) etime = time . time ( ) dns_time = int ( ( etime - stime ) * 1000 ) stime = time . time ( ) r = requests . get ( url , timeout = self . timeout ) r . close ( ) etime = time . time ( ) response_time = int ( ( etime - stime ) * 1000 ) status = 'responsive' phrase = self . status_mapping [ r . status_code ] if re_exp : if not re_exp . findall ( r . text ) : phrase = 'Page content not expected' detail = f'{self.urls[url]}' except dns . resolver . NXDOMAIN : phrase = 'domain not exist' except requests . exceptions . SSLError : status = 'responsive' phrase = 'ssl error' except requests . exceptions . ConnectTimeout : phrase = 'connection timeout' except Exception as e : phrase = str ( e ) . lower ( ) yield WebsiteStatus ( self . track_from , url , status , phrase , dns_time , response_time , detail )
A generator to return status for all URLs at the specific period
A generator to return status for all URLs at the specific period
"""
        A generator to return status for all URLs at the specific period
        :return: A generator yielding WebsiteStatus objects
        """ # We can resolve domain one-off in __init__ but decided not to do so # since this is not a time-critical task and it is handy to do in this way. # Measure DNS query time firstly # We are measuring DNS response in a rough way through dns.resolver module # DNS response time in ms # Total Response time in ms # This should never happen, but just in case.
A generator yielding WebsiteStatus objects
A generator yielding WebsiteStatus objects
self