from pyspark.sql import SparkSession


class Extract:
    """
    Functions to extract data from the source and return the spark dataframe.
    """

    def __init__(self, spark, paths):
        self.spark = spark
        self.paths = paths

    def _get_standard_csv(self, filepath, delimiter=","):
        """
        Function to extract a dataframe from csv file.
        Input: .csv file path
        Option: delimiter
        Output: spark dataframe
        """
        return self.spark.read.format("csv").option("header", "true").option("delimiter", delimiter).load(filepath)

    def get_cities_demographics(self):
        return self._get_standard_csv(filepath=self.paths["us_cities_demographics"], delimiter=";")

    def get_airports_codes(self):
        return self._get_standard_csv(self.paths["airport_codes"])

    def get_immigration(self):
        return self.spark.read.parquet(self.paths["sas_data"])
    
    def get_temperature_data(self):
        return self._get_standard_csv(self.paths["temperature_data"])
from pyspark.sql import SparkSession


class Extract:
    """
    Functions to extract data from the source and return the spark dataframe.
    """

    def __init__(self, spark, paths):
        self.spark = spark
        self.paths = paths

    def _get_standard_csv(self, filepath, delimiter=","):
        """
        Function to extract a dataframe from csv file.
        Input: .csv file path
        Option: delimiter
        Output: spark dataframe
        """
        return self.spark.read.format("csv").option("header", "true").option("delimiter", delimiter).load(filepath)

    def get_cities_demographics(self):
        return self._get_standard_csv(filepath=self.paths["us_cities_demographics"], delimiter=";")

    def get_airports_codes(self):
        return self._get_standard_csv(self.paths["airport_codes"])

    def get_immigration(self):
        return self.spark.read.parquet(self.paths["sas_data"])
    
    def get_temperature_data(self):
        return self._get_standard_csv(self.paths["temperature_data"])
Functions to extract data from the source and return the spark dataframe. Function to extract a dataframe from csv file.         Input: .csv file path         Option: delimiter         Output: spark dataframe