Skip to main content

Utilidades para Google Sheets, Drive y webhooks de Google Chat.

Project description

soxlib

Utilidades para Google Sheets, Google Drive, webhooks de Google Chat y calendario de operaciones con soporte para pandas y pandasql.

Incluye helpers para leer/escribir hojas, subir archivos a Drive, enviar resultados a Chat y actualizar calendarios históricos de forma incremental.

Instalación

pip install soxlib

Para desarrollo local:

pip install -e ".[dev]"

Requisitos previos

  • Python ≥ 3.8
  • Credenciales OAuth: coloca client_secret.json y credentials.json en scripts/utils/ (o pasa una ruta distinta a create_login). El flujo generará token.pickle al primer uso.
  • Archivo scripts/utils/directorio.json con la configuración de IDs de Sheets y webhooks. Ejemplo mínimo:
{
  "mi_tabla": {
    "GOOGLE_SHEET_ID_FUNCIONAL": "1AbcDEFghi...",
    "GOOGLE_SHEET_ID_VISTA_0": "",
    "FILTRO_VISTA_0": "",
    "ARCHIVO": "mi_archivo.csv"
  },
  "mi_webhook": {
    "GOOGLE_SHEET_ID_FUNCIONAL": "https://chat.googleapis.com/v1/spaces/.../messages?key=...&token=..."
  }
}

Módulos

Google Sheets / Drive / Chat (soxlib.gsu)

Función Descripción
lee_hoja_datos(nombre, cloud=True) Lee una hoja (Google Sheets o CSV local) a DataFrame.
actualiza_hoja_datos(df, nombre, overwrite=True, cloud=True) Escribe un DataFrame en Sheets y vista opcional.
enviar_dataframe_a_google_chat(df, webhook_name) Envía un DataFrame tabulado a un webhook de Google Chat.
enviar_mensaje_simple_a_google_chat(msg, webhook_name) Envía un mensaje de texto plano al webhook.
sube_archivo(path, mime_type="image/png") Sube archivos a Drive y devuelve el ID.
sox_enviar_imagen_a_google_chat(path, webhook_name) Sube imagen a Drive y envía enlace al webhook.
create_login(client_secret_path=...) Crea un cliente de Sheets autenticado.
gsheets_to_dataframe(...) Convierte hojas de Google Sheets a DataFrame.
get_all_sheets_data(...) Obtiene datos de todas las hojas de un Spreadsheet.
filtrar_dataframe(df, filtros) Filtra un DataFrame con condiciones dinámicas.
guardar_y_subir_gs(df, nombre) Guarda como CSV local y sube a Google Sheets.
imprimir_tabla(df) Imprime un DataFrame como tabla formateada.
estrella_5_picos_ascii() Devuelve arte ASCII decorativo.

Calendario (soxlib.calendar)

Función Descripción
cal_update(table_1, table_2, table_3, ...) Actualiza un calendario histórico a partir de datos nuevos, respetando excepciones.

Core (soxlib.core)

Función Descripción
add(a, b) Suma dos números (función base de la biblioteca).

Ejemplos rápidos

Google Sheets y Chat

from soxlib import (
    lee_hoja_datos,
    actualiza_hoja_datos,
    enviar_dataframe_a_google_chat,
    sox_enviar_imagen_a_google_chat,
)

df = lee_hoja_datos("mi_tabla")
df_filtrado = df[df["status"] == "OK"]
actualiza_hoja_datos(df_filtrado, "mi_tabla")
enviar_dataframe_a_google_chat(df_filtrado, "mi_webhook")
sox_enviar_imagen_a_google_chat("imagen.png", "mi_webhook")

Calendario

from soxlib import cal_update

resultado = cal_update(
    datos,              # DataFrame con ejecuciones (key, fecha, status)
    calendario,         # DataFrame histórico con columnas de fecha
    especialidad,       # DataFrame auxiliar (o None)
    col_key="JOBNAME",
    col_date="RUN DATE",
    col_info="STATUS",
    month_window=6,
    exceptions=["FORK", "RECUP", "INC"],
)

Estructura del proyecto

soxlib/
├── src/soxlib/
│   ├── __init__.py      # Exports públicos y versión
│   ├── core.py          # Función base (add)
│   ├── gsu.py           # Google Sheets, Drive y Chat
│   └── calendar.py      # Actualización de calendarios
├── tests/
│   ├── test_core.py     # Tests de core
│   ├── test_gsu.py      # Tests de gsu
│   └── test_calendar.py # Tests de calendar
├── pyproject.toml
├── README.md
└── LICENSE

Desarrollo

  1. Crear y activar un entorno virtual.
  2. Instalar dependencias de desarrollo:
    pip install -e ".[dev]"
    
  3. Ejecutar pruebas:
    pytest
    
  4. Construir el paquete:
    python -m build
    
  5. Publicar en TestPyPI/PyPI:
    twine upload dist/*
    

Licencia

GPLv3+. Ver LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

soxlib-0.1.2.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

soxlib-0.1.2-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file soxlib-0.1.2.tar.gz.

File metadata

  • Download URL: soxlib-0.1.2.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for soxlib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4e2449c2eafc0c2813618e14d7139f71d258d86457ad1f887ffac1067f9991f7
MD5 dae4fe87c6ab4b2e61dae415bd3824f3
BLAKE2b-256 c9ce935a778ea322e22831faa004759004cd611f0f6a3d5596197fac3a1f4fae

See more details on using hashes here.

File details

Details for the file soxlib-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: soxlib-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for soxlib-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 653b5aeb6c62fb286d32c5af620e70f33eb902dabaaa25d088f13cea2ff7eb89
MD5 d834f2e0d0df14216e3818760f97f119
BLAKE2b-256 97ca4b92120e25cb6695301b1ac40511897166974e3de4ff124ced99d1415aab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page