from datetime import datetime


def extract_date_sitename(directory_path,
                          sitename_location,
                          datetime_location):
    """Extract datetime and sitename from directory path names.

    Parameters
    -----------
    directory_path : string
        A path to the directory name
    sitename_location : index list
        Index of sitename location in directory path name
    datetime_location : index list
        Index of datetime location in directory path name

    Returns
    -----------
    list : list of the datetime location and sitename information
    """
    # Create an empty list to append both sitename and date information
    sitename_date = []

    # Assign datetime location to an object and specify datetime format
    date_location = directory_path[datetime_location[0]: datetime_location[1]]
    format = "%Y%m%d"

    # Create a date varaiable using new object and the datetime format
    date = datetime.strptime(date_location, format)

    # Create a location variable called "site"
    site = directory_path[sitename_location[0]: sitename_location[1]]

    # Append site and date variables to list
    sitename_date.append(site)
    sitename_date.append(date)
    
    # Return the populated sitename_date list
    return sitename_date