92 lines
3 KiB
Python
92 lines
3 KiB
Python
|
|
"""
|
||
|
|
Sincroniza datos de Planner con el tablero HTML v7 (sin modificar el HTML).
|
||
|
|
|
||
|
|
Flujo:
|
||
|
|
python script.py # extrae datos y genera Excel
|
||
|
|
python sync_dashboard.py # genera TSV y actualiza Google Sheets
|
||
|
|
|
||
|
|
El HTML sigue leyendo la misma URL publicada de Google Sheets.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
import sys
|
||
|
|
|
||
|
|
from config import data_source_label, validate_config
|
||
|
|
from export.google_sheet_sync import GoogleSheetSyncError, sync_rows_to_google_sheet, validate_google_config
|
||
|
|
from export.rtc_tsv_exporter import export_rtc_tsv, projects_to_rows
|
||
|
|
from services.data_factory import create_data_service
|
||
|
|
|
||
|
|
|
||
|
|
def sync_dashboard(*, skip_google: bool = False) -> None:
|
||
|
|
missing = validate_config()
|
||
|
|
if missing:
|
||
|
|
print("[ERROR] Faltan variables en .env:")
|
||
|
|
for var in missing:
|
||
|
|
print(f" - {var}")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
print("\n[...] Obteniendo proyectos y tareas...")
|
||
|
|
service = create_data_service()
|
||
|
|
projects = service.get_all_projects()
|
||
|
|
|
||
|
|
if not projects:
|
||
|
|
print("[AVISO] No se encontraron proyectos.")
|
||
|
|
sys.exit(0)
|
||
|
|
|
||
|
|
total_tasks = sum(p["total_tareas"] for p in projects)
|
||
|
|
print(f"[OK] {len(projects)} proyectos, {total_tasks} tareas obtenidas.")
|
||
|
|
|
||
|
|
rows = projects_to_rows(projects)
|
||
|
|
tsv_path = export_rtc_tsv(projects)
|
||
|
|
print(f"[OK] TSV generado: {tsv_path}")
|
||
|
|
print(f" {len(rows) - 1} fila(s) de tareas listas para el tablero.")
|
||
|
|
|
||
|
|
if skip_google:
|
||
|
|
print("\n[AVISO] Modo --tsv-only: no se sincronizo Google Sheets.")
|
||
|
|
print(" Importa el TSV a la hoja que publica el HTML.")
|
||
|
|
return
|
||
|
|
|
||
|
|
google_missing = validate_google_config()
|
||
|
|
if google_missing:
|
||
|
|
print("\n[AVISO] Google Sheets no configurado:")
|
||
|
|
for var in google_missing:
|
||
|
|
print(f" - {var}")
|
||
|
|
print("\nEl TSV local ya esta listo. Para automatizar:")
|
||
|
|
print(" 1. Crea una cuenta de servicio en Google Cloud")
|
||
|
|
print(" 2. Comparte la hoja con el email de la cuenta de servicio")
|
||
|
|
print(" 3. Completa GOOGLE_SPREADSHEET_ID y GOOGLE_CREDENTIALS_PATH en .env")
|
||
|
|
print(" 4. Vuelve a ejecutar: python sync_dashboard.py")
|
||
|
|
return
|
||
|
|
|
||
|
|
try:
|
||
|
|
written = sync_rows_to_google_sheet(rows)
|
||
|
|
print(f"[OK] Google Sheets actualizado ({written} filas de tareas).")
|
||
|
|
print(" Abre Tablero_proyectos_v7.html para ver los datos de Planner.")
|
||
|
|
except GoogleSheetSyncError as exc:
|
||
|
|
print(f"[ERROR] No se pudo sincronizar Google Sheets: {exc}")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> None:
|
||
|
|
parser = argparse.ArgumentParser(
|
||
|
|
description="Sincroniza Planner con el tablero HTML v7 via Google Sheets"
|
||
|
|
)
|
||
|
|
parser.add_argument(
|
||
|
|
"--tsv-only",
|
||
|
|
action="store_true",
|
||
|
|
help="Solo genera el archivo TSV local, sin subir a Google Sheets",
|
||
|
|
)
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
print("=" * 50)
|
||
|
|
print(" Sync tablero RTC (HTML v7)")
|
||
|
|
print(f" Fuente: {data_source_label()}")
|
||
|
|
print("=" * 50)
|
||
|
|
|
||
|
|
sync_dashboard(skip_google=args.tsv_only)
|
||
|
|
print("\n[OK] Proceso completado.")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|