PyFunceble/database.py
def add(self):
        """
        Add the currently tested element into the database.
        """

        if self._authorization():
            # We are authorized to work.

            if self.epoch < int(PyFunceble.time()):
                state = "past"
            else:
                state = "future"

            if self.is_in_database():
                # The element we are working with is in the database.

                if (
                    str(self.epoch)
                    != PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]][
                        PyFunceble.INTERN["to_test"]
                    ]["epoch"]
                ):
                    # The given epoch is diffent from the one saved.

                    # We update it.
                    PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]][
                        PyFunceble.INTERN["to_test"]
                    ].update(
                        {
                            "epoch": str(self.epoch),
                            "state": state,
                            "expiration_date": self.expiration_date,
                        }
                    )

                elif self.is_time_older():
                    # The expiration date from the database is in the past.

                    if (
                        PyFunceble.INTERN["whois_db"][
                            PyFunceble.INTERN["file_to_test"]
                        ][PyFunceble.INTERN["to_test"]]["state"]
                        != "past"
                    ):  # pragma: no cover
                        # The state of the element in the datbase is not
                        # equal to `past`.

                        # We update it to `past`.
                        PyFunceble.INTERN["whois_db"][
                            PyFunceble.INTERN["file_to_test"]
                        ][PyFunceble.INTERN["to_test"]].update({"state": "past"})
                elif (
                    PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]][
                        PyFunceble.INTERN["to_test"]
                    ]["state"]
                    != "future"
                ):
                    # * The expiration date from the database is in the future.
                    # and
                    # * The state of the element in the database is not
                    # equal to `future`.

                    # We update it to `future`.
                    PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]][
                        PyFunceble.INTERN["to_test"]
                    ].update({"state": "future"})
            else:
                # The element we are working with is not in the database.

                if (
                    not PyFunceble.INTERN["file_to_test"]
                    in PyFunceble.INTERN["whois_db"]
                ):
                    # The file path is not in the database.

                    # We initiate it.
                    PyFunceble.INTERN["whois_db"][
                        PyFunceble.INTERN["file_to_test"]
                    ] = {}

                # We create the first dataset.
                PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]].update(
                    {
                        PyFunceble.INTERN["to_test"]: {
                            "epoch": str(self.epoch),
                            "state": state,
                            "expiration_date": self.expiration_date,
                        }
                    }
                )

            # We do a safety backup of our database.
            self._backup()
def add(self):
        if self._authorization():
            # We are authorized to work.

            if self.epoch < int(PyFunceble.time()):
                state = "past"
            else:
                state = "future"

            if self.is_in_database():
                # The element we are working with is in the database.

                if (
                    str(self.epoch)
                    != PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]][
                        PyFunceble.INTERN["to_test"]
                    ]["epoch"]
                ):
                    # The given epoch is diffent from the one saved.

                    # We update it.
                    PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]][
                        PyFunceble.INTERN["to_test"]
                    ].update(
                        {
                            "epoch": str(self.epoch),
                            "state": state,
                            "expiration_date": self.expiration_date,
                        }
                    )

                elif self.is_time_older():
                    # The expiration date from the database is in the past.

                    if (
                        PyFunceble.INTERN["whois_db"][
                            PyFunceble.INTERN["file_to_test"]
                        ][PyFunceble.INTERN["to_test"]]["state"]
                        != "past"
                    ):  # pragma: no cover
                        # The state of the element in the datbase is not
                        # equal to `past`.

                        # We update it to `past`.
                        PyFunceble.INTERN["whois_db"][
                            PyFunceble.INTERN["file_to_test"]
                        ][PyFunceble.INTERN["to_test"]].update({"state": "past"})
                elif (
                    PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]][
                        PyFunceble.INTERN["to_test"]
                    ]["state"]
                    != "future"
                ):
                    # * The expiration date from the database is in the future.
                    # and
                    # * The state of the element in the database is not
                    # equal to `future`.

                    # We update it to `future`.
                    PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]][
                        PyFunceble.INTERN["to_test"]
                    ].update({"state": "future"})
            else:
                # The element we are working with is not in the database.

                if (
                    not PyFunceble.INTERN["file_to_test"]
                    in PyFunceble.INTERN["whois_db"]
                ):
                    # The file path is not in the database.

                    # We initiate it.
                    PyFunceble.INTERN["whois_db"][
                        PyFunceble.INTERN["file_to_test"]
                    ] = {}

                # We create the first dataset.
                PyFunceble.INTERN["whois_db"][PyFunceble.INTERN["file_to_test"]].update(
                    {
                        PyFunceble.INTERN["to_test"]: {
                            "epoch": str(self.epoch),
                            "state": state,
                            "expiration_date": self.expiration_date,
                        }
                    }
                )

            # We do a safety backup of our database.
            self._backup()
def add ( self ) : if self . _authorization ( ) : # We are authorized to work. if self . epoch < int ( PyFunceble . time ( ) ) : state = "past" else : state = "future" if self . is_in_database ( ) : # The element we are working with is in the database. if ( str ( self . epoch ) != PyFunceble . INTERN [ "whois_db" ] [ PyFunceble . INTERN [ "file_to_test" ] ] [ PyFunceble . INTERN [ "to_test" ] ] [ "epoch" ] ) : # The given epoch is diffent from the one saved. # We update it. PyFunceble . INTERN [ "whois_db" ] [ PyFunceble . INTERN [ "file_to_test" ] ] [ PyFunceble . INTERN [ "to_test" ] ] . update ( { "epoch" : str ( self . epoch ) , "state" : state , "expiration_date" : self . expiration_date , } ) elif self . is_time_older ( ) : # The expiration date from the database is in the past. if ( PyFunceble . INTERN [ "whois_db" ] [ PyFunceble . INTERN [ "file_to_test" ] ] [ PyFunceble . INTERN [ "to_test" ] ] [ "state" ] != "past" ) : # pragma: no cover # The state of the element in the datbase is not # equal to `past`. # We update it to `past`. PyFunceble . INTERN [ "whois_db" ] [ PyFunceble . INTERN [ "file_to_test" ] ] [ PyFunceble . INTERN [ "to_test" ] ] . update ( { "state" : "past" } ) elif ( PyFunceble . INTERN [ "whois_db" ] [ PyFunceble . INTERN [ "file_to_test" ] ] [ PyFunceble . INTERN [ "to_test" ] ] [ "state" ] != "future" ) : # * The expiration date from the database is in the future. # and # * The state of the element in the database is not # equal to `future`. # We update it to `future`. PyFunceble . INTERN [ "whois_db" ] [ PyFunceble . INTERN [ "file_to_test" ] ] [ PyFunceble . INTERN [ "to_test" ] ] . update ( { "state" : "future" } ) else : # The element we are working with is not in the database. if ( not PyFunceble . INTERN [ "file_to_test" ] in PyFunceble . INTERN [ "whois_db" ] ) : # The file path is not in the database. # We initiate it. PyFunceble . INTERN [ "whois_db" ] [ PyFunceble . INTERN [ "file_to_test" ] ] = { } # We create the first dataset. PyFunceble . INTERN [ "whois_db" ] [ PyFunceble . INTERN [ "file_to_test" ] ] . update ( { PyFunceble . INTERN [ "to_test" ] : { "epoch" : str ( self . epoch ) , "state" : state , "expiration_date" : self . expiration_date , } } ) # We do a safety backup of our database. self . _backup ( )
Add the currently tested element into the database.
Add the currently tested element into the database .