24 lines
688 B
Python
24 lines
688 B
Python
import os
|
|
|
|
import pandas as pd
|
|
|
|
from .config import REQUIRED_COLUMNS
|
|
|
|
|
|
def cargar_mensajes(path):
|
|
ext = os.path.splitext(path)[1].lower()
|
|
if ext == ".csv":
|
|
df = pd.read_csv(path, dtype=str)
|
|
elif ext in [".xls", ".xlsx"]:
|
|
df = pd.read_excel(path, dtype=str)
|
|
else:
|
|
raise ValueError("Formato no soportado. Usa .csv o .xlsx")
|
|
|
|
df.columns = [column.strip() for column in df.columns]
|
|
missing = REQUIRED_COLUMNS - set(df.columns)
|
|
if missing:
|
|
raise ValueError(f"Columnas faltantes en '{path}': {missing}")
|
|
|
|
df["tipo"] = df["tipo"].str.strip().str.lower()
|
|
return df[df["tipo"].isin(["contacto", "grupo"])].reset_index(drop=True)
|