PyFunceble/expiration_date.py
def _extract(self):  # pragma: no cover
        """
        Extract the expiration date from the whois record.

        :return: The status of the domain.
        :rtype: str
        """

        # We try to get the expiration date from the database.
        expiration_date_from_database = Whois().get_expiration_date()

        if expiration_date_from_database:
            # The hash of the current whois record did not changed and the
            # expiration date from the database is not empty not equal to
            # None or False.

            # We generate the files and print the status.
            # It's an active element!
            Generate(
                PyFunceble.STATUS["official"]["up"],
                "WHOIS",
                expiration_date_from_database,
            ).status_file()

            # We handle und return the official up status.
            return PyFunceble.STATUS["official"]["up"]

        # We get the whois record.
        self.whois_record = Lookup().whois(PyFunceble.INTERN["referer"])

        # We list the list of regex which will help us get an unformatted expiration date.
        to_match = [
            r"expire:(.*)",
            r"expire on:(.*)",
            r"Expiry Date:(.*)",
            r"free-date(.*)",
            r"expires:(.*)",
            r"Expiration date:(.*)",
            r"Expiry date:(.*)",
            r"Expire Date:(.*)",
            r"renewal date:(.*)",
            r"Expires:(.*)",
            r"validity:(.*)",
            r"Expiration Date             :(.*)",
            r"Expiry :(.*)",
            r"expires at:(.*)",
            r"domain_datebilleduntil:(.*)",
            r"Data de expiração \/ Expiration Date \(dd\/mm\/yyyy\):(.*)",
            r"Fecha de expiración \(Expiration date\):(.*)",
            r"\[Expires on\](.*)",
            r"Record expires on(.*)(\(YYYY-MM-DD\))",
            r"status:      OK-UNTIL(.*)",
            r"renewal:(.*)",
            r"expires............:(.*)",
            r"expire-date:(.*)",
            r"Exp date:(.*)",
            r"Valid-date(.*)",
            r"Expires On:(.*)",
            r"Fecha de vencimiento:(.*)",
            r"Expiration:.........(.*)",
            r"Fecha de Vencimiento:(.*)",
            r"Registry Expiry Date:(.*)",
            r"Expires on..............:(.*)",
            r"Expiration Time:(.*)",
            r"Expiration Date:(.*)",
            r"Expired:(.*)",
            r"Date d'expiration:(.*)",
            r"expiration date:(.*)",
        ]

        if self.whois_record:
            # The whois record is not empty.

            if "current_test_data" in PyFunceble.INTERN:
                # The end-user want more information whith his test.

                # We update the whois_record index.
                PyFunceble.INTERN["current_test_data"][
                    "whois_record"
                ] = self.whois_record

            for string in to_match:
                # We loop through the list of regex.

                # We try tro extract the expiration date from the WHOIS record.
                expiration_date = Regex(
                    self.whois_record, string, return_data=True, rematch=True, group=0
                ).match()

                if expiration_date:
                    # The expiration date could be extracted.

                    # We get the extracted expiration date.
                    self.expiration_date = expiration_date[0].strip()

                    # We initate a regex which will help us know if a number
                    # is present into the extracted expiration date.
                    regex_rumbers = r"[0-9]"

                    if Regex(
                        self.expiration_date, regex_rumbers, return_data=False
                    ).match():
                        # The extracted expiration date has a number.

                        # We format the extracted expiration date.
                        self.expiration_date = self._format()

                        if (
                            self.expiration_date
                            and not Regex(
                                self.expiration_date,
                                r"[0-9]{2}\-[a-z]{3}\-2[0-9]{3}",
                                return_data=False,
                            ).match()
                        ):
                            # The formatted expiration date does not match our unified format.

                            # We log the problem.
                            Logs().expiration_date(self.expiration_date)

                            # We log the whois record.
                            Logs().whois(self.whois_record)

                        if "current_test_data" in PyFunceble.INTERN:
                            # The end-user want more information whith his test.

                            # We update the expiration_date index.
                            PyFunceble.INTERN["current_test_data"][
                                "expiration_date"
                            ] = self.expiration_date

                        # We generate the files and print the status.
                        # It's an active element!
                        Generate(
                            PyFunceble.STATUS["official"]["up"],
                            "WHOIS",
                            self.expiration_date,
                        ).status_file()

                        # We log the whois record.
                        Logs().whois(self.whois_record)

                        # We save the whois record into the database.
                        Whois(expiration_date=self.expiration_date).add()

                        # We handle und return the official up status.
                        return PyFunceble.STATUS["official"]["up"]

                    # The extracted expiration date does not have a number.

                    # We log the whois record.
                    Logs().whois(self.whois_record)

                    # We return None, we could not get the expiration date.
                    return None

        # The whois record is empty.

        # We return None, we could not get the whois record.
        return None
def _extract(self):  # pragma: no cover
        """
        Extract the expiration date from the whois record.

        :return: The status of the domain.
        :rtype: str
        """

        # We try to get the expiration date from the database.
        expiration_date_from_database = Whois().get_expiration_date()

        if expiration_date_from_database:
            # The hash of the current whois record did not changed and the
            # expiration date from the database is not empty not equal to
            # None or False.

            # We generate the files and print the status.
            # It's an active element!
            Generate(
                PyFunceble.STATUS["official"]["up"],
                "WHOIS",
                expiration_date_from_database,
            ).status_file()

            # We handle und return the official up status.
            return PyFunceble.STATUS["official"]["up"]

        # We get the whois record.
        self.whois_record = Lookup().whois(PyFunceble.INTERN["referer"])

        # We list the list of regex which will help us get an unformatted expiration date.
        to_match = [
            r"expire:(.*)",
            r"expire on:(.*)",
            r"Expiry Date:(.*)",
            r"free-date(.*)",
            r"expires:(.*)",
            r"Expiration date:(.*)",
            r"Expiry date:(.*)",
            r"Expire Date:(.*)",
            r"renewal date:(.*)",
            r"Expires:(.*)",
            r"validity:(.*)",
            r"Expiration Date             :(.*)",
            r"Expiry :(.*)",
            r"expires at:(.*)",
            r"domain_datebilleduntil:(.*)",
            r"Data de expiração \/ Expiration Date \(dd\/mm\/yyyy\):(.*)",
            r"Fecha de expiración \(Expiration date\):(.*)",
            r"\[Expires on\](.*)",
            r"Record expires on(.*)(\(YYYY-MM-DD\))",
            r"status:      OK-UNTIL(.*)",
            r"renewal:(.*)",
            r"expires............:(.*)",
            r"expire-date:(.*)",
            r"Exp date:(.*)",
            r"Valid-date(.*)",
            r"Expires On:(.*)",
            r"Fecha de vencimiento:(.*)",
            r"Expiration:.........(.*)",
            r"Fecha de Vencimiento:(.*)",
            r"Registry Expiry Date:(.*)",
            r"Expires on..............:(.*)",
            r"Expiration Time:(.*)",
            r"Expiration Date:(.*)",
            r"Expired:(.*)",
            r"Date d'expiration:(.*)",
            r"expiration date:(.*)",
        ]

        if self.whois_record:
            # The whois record is not empty.

            if "current_test_data" in PyFunceble.INTERN:
                # The end-user want more information whith his test.

                # We update the whois_record index.
                PyFunceble.INTERN["current_test_data"][
                    "whois_record"
                ] = self.whois_record

            for string in to_match:
                # We loop through the list of regex.

                # We try tro extract the expiration date from the WHOIS record.
                expiration_date = Regex(
                    self.whois_record, string, return_data=True, rematch=True, group=0
                ).match()

                if expiration_date:
                    # The expiration date could be extracted.

                    # We get the extracted expiration date.
                    self.expiration_date = expiration_date[0].strip()

                    # We initate a regex which will help us know if a number
                    # is present into the extracted expiration date.
                    regex_rumbers = r"[0-9]"

                    if Regex(
                        self.expiration_date, regex_rumbers, return_data=False
                    ).match():
                        # The extracted expiration date has a number.

                        # We format the extracted expiration date.
                        self.expiration_date = self._format()

                        if (
                            self.expiration_date
                            and not Regex(
                                self.expiration_date,
                                r"[0-9]{2}\-[a-z]{3}\-2[0-9]{3}",
                                return_data=False,
                            ).match()
                        ):
                            # The formatted expiration date does not match our unified format.

                            # We log the problem.
                            Logs().expiration_date(self.expiration_date)

                            # We log the whois record.
                            Logs().whois(self.whois_record)

                        if "current_test_data" in PyFunceble.INTERN:
                            # The end-user want more information whith his test.

                            # We update the expiration_date index.
                            PyFunceble.INTERN["current_test_data"][
                                "expiration_date"
                            ] = self.expiration_date

                        # We generate the files and print the status.
                        # It's an active element!
                        Generate(
                            PyFunceble.STATUS["official"]["up"],
                            "WHOIS",
                            self.expiration_date,
                        ).status_file()

                        # We log the whois record.
                        Logs().whois(self.whois_record)

                        # We save the whois record into the database.
                        Whois(expiration_date=self.expiration_date).add()

                        # We handle und return the official up status.
                        return PyFunceble.STATUS["official"]["up"]

                    # The extracted expiration date does not have a number.

                    # We log the whois record.
                    Logs().whois(self.whois_record)

                    # We return None, we could not get the expiration date.
                    return None

        # The whois record is empty.

        # We return None, we could not get the whois record.
        return None
def _extract ( self ) : # pragma: no cover # We try to get the expiration date from the database. expiration_date_from_database = Whois ( ) . get_expiration_date ( ) if expiration_date_from_database : # The hash of the current whois record did not changed and the # expiration date from the database is not empty not equal to # None or False. # We generate the files and print the status. # It's an active element! Generate ( PyFunceble . STATUS [ "official" ] [ "up" ] , "WHOIS" , expiration_date_from_database , ) . status_file ( ) # We handle und return the official up status. return PyFunceble . STATUS [ "official" ] [ "up" ] # We get the whois record. self . whois_record = Lookup ( ) . whois ( PyFunceble . INTERN [ "referer" ] ) # We list the list of regex which will help us get an unformatted expiration date. to_match = [ r"expire:(.*)" , r"expire on:(.*)" , r"Expiry Date:(.*)" , r"free-date(.*)" , r"expires:(.*)" , r"Expiration date:(.*)" , r"Expiry date:(.*)" , r"Expire Date:(.*)" , r"renewal date:(.*)" , r"Expires:(.*)" , r"validity:(.*)" , r"Expiration Date             :(.*)" , r"Expiry :(.*)" , r"expires at:(.*)" , r"domain_datebilleduntil:(.*)" , r"Data de expiração \/ Expiration Date \(dd\/mm\/yyyy\):(.*)", r"Fecha de expiración \(Expiration date\):(.*)", r"\[Expires on\](.*)" , r"Record expires on(.*)(\(YYYY-MM-DD\))" , r"status:      OK-UNTIL(.*)" , r"renewal:(.*)" , r"expires............:(.*)" , r"expire-date:(.*)" , r"Exp date:(.*)" , r"Valid-date(.*)" , r"Expires On:(.*)" , r"Fecha de vencimiento:(.*)" , r"Expiration:.........(.*)" , r"Fecha de Vencimiento:(.*)" , r"Registry Expiry Date:(.*)" , r"Expires on..............:(.*)" , r"Expiration Time:(.*)" , r"Expiration Date:(.*)" , r"Expired:(.*)" , r"Date d'expiration:(.*)" , r"expiration date:(.*)" , ] if self . whois_record : # The whois record is not empty. if "current_test_data" in PyFunceble . INTERN : # The end-user want more information whith his test. # We update the whois_record index. PyFunceble . INTERN [ "current_test_data" ] [ "whois_record" ] = self . whois_record for string in to_match : # We loop through the list of regex. # We try tro extract the expiration date from the WHOIS record. expiration_date = Regex ( self . whois_record , string , return_data = True , rematch = True , group = 0 ) . match ( ) if expiration_date : # The expiration date could be extracted. # We get the extracted expiration date. self . expiration_date = expiration_date [ 0 ] . strip ( ) # We initate a regex which will help us know if a number # is present into the extracted expiration date. regex_rumbers = r"[0-9]" if Regex ( self . expiration_date , regex_rumbers , return_data = False ) . match ( ) : # The extracted expiration date has a number. # We format the extracted expiration date. self . expiration_date = self . _format ( ) if ( self . expiration_date and not Regex ( self . expiration_date , r"[0-9]{2}\-[a-z]{3}\-2[0-9]{3}" , return_data = False , ) . match ( ) ) : # The formatted expiration date does not match our unified format. # We log the problem. Logs ( ) . expiration_date ( self . expiration_date ) # We log the whois record. Logs ( ) . whois ( self . whois_record ) if "current_test_data" in PyFunceble . INTERN : # The end-user want more information whith his test. # We update the expiration_date index. PyFunceble . INTERN [ "current_test_data" ] [ "expiration_date" ] = self . expiration_date # We generate the files and print the status. # It's an active element! Generate ( PyFunceble . STATUS [ "official" ] [ "up" ] , "WHOIS" , self . expiration_date , ) . status_file ( ) # We log the whois record. Logs ( ) . whois ( self . whois_record ) # We save the whois record into the database. Whois ( expiration_date = self . expiration_date ) . add ( ) # We handle und return the official up status. return PyFunceble . STATUS [ "official" ] [ "up" ] # The extracted expiration date does not have a number. # We log the whois record. Logs ( ) . whois ( self . whois_record ) # We return None, we could not get the expiration date. return None # The whois record is empty. # We return None, we could not get the whois record. return None
Extract the expiration date from the whois record.

        :return: The status of the domain.
        :rtype: str
Extract the expiration date from the whois record .