(
        self,
        api_key=None,
        source="acs5",
        years=None,
        data_dir=None,
        force=False
    )
Configuration.
Configuration.
Configuration .
def __init__(
        self,
        api_key=None,
        source="acs5",
        years=None,
        data_dir=None,
        force=False
    ):
        """
        Configuration.
        """
        # Set the inputs
        self.CENSUS_API_KEY = os.getenv("CENSUS_API_KEY", api_key)
        if not self.CENSUS_API_KEY:
            raise NotImplementedError("Census API key required. Pass it as the first argument.")
        self.source = source
        self.force = force

        #
        # Allow custom years for data download, defaulting to most recent year
        #

        # If they want all the years, give it to them.
        if years == "all":
            self.years_to_download = self.YEAR_LIST
        # If the user provides a year give them that.
        elif isinstance(years, int):
            self.years_to_download = [years]
        # Or if they provide years as a list, give those then.
        elif isinstance(years, list):
            self.years_to_download = list(map(int, years))
        # If they provided nothing, default to the latest year of data
        elif years is None:
            self.years_to_download = [max(self.YEAR_LIST), ]

        # Validate the years
        for year in self.years_to_download:
            if year not in self.YEAR_LIST:
                error_msg = ("Data only available for the years"
                             f"{self.YEAR_LIST[-1]}-{self.YEAR_LIST[0]}.")
                raise NotImplementedError(error_msg)

        # Set the data directories
        if data_dir:
            self.data_dir = pathlib.Path(str(data_dir))
        else:
            self.data_dir = self.PARENT_DIR.joinpath("data")
        self.raw_data_dir = self.data_dir.joinpath("raw")
        self.processed_data_dir = self.data_dir.joinpath("processed")

        # Make sure they exist
        if not self.data_dir.exists():
            self.data_dir.mkdir()
        if not self.raw_data_dir.exists():
            self.raw_data_dir.mkdir()
        if not self.processed_data_dir.exists():
            self.processed_data_dir.mkdir()
def __init__ ( self , api_key = None , source = "acs5" , years = None , data_dir = None , force = False ) : # Set the inputs self . CENSUS_API_KEY = os . getenv ( "CENSUS_API_KEY" , api_key ) if not self . CENSUS_API_KEY : raise NotImplementedError ( "Census API key required. Pass it as the first argument." ) self . source = source self . force = force # # Allow custom years for data download, defaulting to most recent year # # If they want all the years, give it to them. if years == "all" : self . years_to_download = self . YEAR_LIST # If the user provides a year give them that. elif isinstance ( years , int ) : self . years_to_download = [ years ] # Or if they provide years as a list, give those then. elif isinstance ( years , list ) : self . years_to_download = list ( map ( int , years ) ) # If they provided nothing, default to the latest year of data elif years is None : self . years_to_download = [ max ( self . YEAR_LIST ) , ] # Validate the years for year in self . years_to_download : if year not in self . YEAR_LIST : error_msg = ( "Data only available for the years" f"{self.YEAR_LIST[-1]}-{self.YEAR_LIST[0]}." ) raise NotImplementedError ( error_msg ) # Set the data directories if data_dir : self . data_dir = pathlib . Path ( str ( data_dir ) ) else : self . data_dir = self . PARENT_DIR . joinpath ( "data" ) self . raw_data_dir = self . data_dir . joinpath ( "raw" ) self . processed_data_dir = self . data_dir . joinpath ( "processed" ) # Make sure they exist if not self . data_dir . exists ( ) : self . data_dir . mkdir ( ) if not self . raw_data_dir . exists ( ) : self . raw_data_dir . mkdir ( ) if not self . processed_data_dir . exists ( ) : self . processed_data_dir . mkdir ( )