import pandas as pd


#######################################################################
class BasicData(object):
    """
    Basic class for working with data.
    """

    #----------------------------------------------------------------------
    def __init__(self, logger, config, type, filepath, filename):
        """
        Constructor
        """
        self.logger = logger
        self.config = config
        self.type = type
        self.filepath = filepath
        self.filename = filename
        
        if type == "bin":
            self.data = pd.read_pickle("{}.{}".format(filepath, type))
        elif type == "csv":
            self.data = pd.read_csv("{}.{}".format(filepath, type), header=0), names=["raw_domain"])

    #----------------------------------------------------------------------
    def save_data_to_disk(self, filename):
        """
        Save data to disk in pickled form and to csv.
        """
        self.logger.debug("Saving data to {}...".format(filename))
        self.data.to_pickle("{}.bin".format(filename))

        with open("{}.csv".format(filename), "w", newline="") as out:
            out.write(self.data.to_csv(index=False))