from datetime import datetime


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

    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 site names and datetime information
    """
    # Create an empty list to append sitename and date information
    site_name_date_list = []

    # Assign datetime location to an object
    date_location = directory_path[datetime_location[0]: datetime_location[1]]

    # Specify datetime format
    format = "%Y%m%d"

    # Use datetime and format to create date varibale
    date = datetime.strptime(date_location, format)

    # Assign sitename information to a variable
    site = directory_path[sitename_location[0]: sitename_location[1]]

    # Append site variable to list
    site_name_date_list.append(site)

    # Append date variable to list
    site_name_date_list.append(date)

    return site_name_date_list