from pathlib import Path


def extract_params(s3_filepath):
    """Extrai mês, ano e periodicidade do caminho do bucket."""
    prefix = "tcmbapublicconsultation/"
    start_index = s3_filepath.find(prefix) + len(prefix)
    relative_path = Path(s3_filepath[start_index:])
    folders = relative_path.parts
    year = folders[0]
    period = folders[1]
    month = None
    if period == "mensal":
        month = folders[2]
    return {"year": year, "period": period, "month": month}