a76760edba
Funciones reutilizables creadas esta sesion para el sistema self-hosted de contactos/calendario (Xandikos) y la app osint_web: - grupo dav (infra): split_vcards, split_vevents_to_vcalendars, extract_or_make_uid, carddav_put_vcard, caldav_put_event, dav_list_resources, dav_get_resource, dav_list_calendars - pipelines: import_vcf_to_carddav, import_ics_to_caldav - obsidian: build_obsidian_graph (grafo agregado del vault)
4.1 KiB
4.1 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| caldav_put_event | function | py | infra | 1.0.0 | impure | def caldav_put_event(base_url: str, username: str, password: str, collection_path: str, uid: str, vcalendar_text: str, *, timeout_s: float = 20.0, verify_tls: bool = True) -> dict | Sube (HTTP PUT) un VCALENDAR (con un VEVENT) a una coleccion CalDAV con HTTP Basic auth. Construye el header Authorization: Basic base64(user:pass) a mano con stdlib. El nombre del recurso se deriva del UID saneado (safe(uid)+'.ics'). verify_tls=True por defecto. Idempotente por UID: re-subir el mismo UID sobrescribe el recurso. Maneja errores sin lanzar (HTTPError/URLError -> {status:'error'}). Solo stdlib (urllib, base64, re, ssl). Probado contra Xandikos. |
|
false | error_go_core |
|
|
dict. En exito: {status:'ok', http_status:int, url:str}. En error (sin lanzar): {status:'error', error:str, http_status:int|None}. http_status es el codigo HTTP devuelto (201 created / 204 no content tipico en CalDAV). | true |
|
python/functions/infra/caldav_put_event_test.py | python/functions/infra/caldav_put_event.py |
Ejemplo
import sys
sys.path.insert(0, "python/functions")
from infra.pass_get_secret import pass_get_secret
from infra.caldav_put_event import caldav_put_event
pw = pass_get_secret("dav/xandikos-enmanuel")["value"] # NO logear
cal = (
"BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//x//EN\r\nCALSCALE:GREGORIAN\r\n"
"BEGIN:VEVENT\r\nUID:evt-1@google.com\r\nSUMMARY:Reunion\r\n"
"DTSTART:20260101T100000Z\r\nDTEND:20260101T110000Z\r\nEND:VEVENT\r\n"
"END:VCALENDAR\r\n"
)
res = caldav_put_event(
base_url="https://dav-eedeb681c4ab89ab8e444ac9.organic-machine.com",
username="enmanuel",
password=pw,
collection_path="/enmanuel/calendars/calendar/",
uid="evt-1@google.com",
vcalendar_text=cal,
)
print(res) # {"status": "ok", "http_status": 201, "url": ".../evt-1_google.com.ics"}
Cuando usarla
Cuando quieres subir un evento individual a Xandikos (u otro servidor CalDAV)
por HTTP. Es la primitiva de escritura de calendario del grupo dav; el
pipeline import_ics_to_caldav la invoca por cada VCALENDAR producido por
split_vevents_to_vcalendars. Antes de llamarla, resuelve el UID con
extract_or_make_uid y la password con pass_get_secret.
Gotchas
- Escritura remota real: re-subir el mismo UID SOBRESCRIBE el recurso (idempotente, no duplica).
- El VCALENDAR debe ser completo y autonomo (header + VTIMEZONE necesarias + un VEVENT). Subir un VEVENT suelto sin envolver en VCALENDAR fallara.
- Contrasena en header Basic sobre TLS; nunca hardcodear, leer de
pass. No se logea. verify_tls=Falsesolo en pruebas; abre MITM.- Devuelve dict (status/http_status/error), NO un int crudo: captura errores HTTP/red sin lanzar.