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)
3.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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| split_vevents_to_vcalendars | function | py | infra | 1.0.0 | pure | def split_vevents_to_vcalendars(ics_text: str, prodid: str = '-//xandikos-migracion//google-export//EN') -> list | Divide un .ics (un VCALENDAR con N VEVENT) en N VCALENDARs independientes, cada uno con un unico VEVENT, header VERSION/PRODID/CALSCALE y las VTIMEZONE del original. Pura, solo stdlib (re). Util para importar a CalDAV un .ics exportado de Google Calendar que mete todos los eventos en un solo VCALENDAR: cada salida se sube como recurso .ics independiente. Normaliza saltos de linea a CRLF (RFC 5545). |
|
false |
|
|
list[str]. Cada elemento es un VCALENDAR completo y autonomo ('BEGIN:VCALENDAR'..'END:VCALENDAR' terminado en CRLF) con header VERSION:2.0 / PRODID / CALSCALE:GREGORIAN, las VTIMEZONE del original (si las habia, replicadas en cada salida) y un unico VEVENT. Lista vacia si no hay ningun VEVENT. | true |
|
python/functions/infra/split_vevents_to_vcalendars_test.py | python/functions/infra/split_vevents_to_vcalendars.py |
Ejemplo
import sys
sys.path.insert(0, "python/functions")
from infra.split_vevents_to_vcalendars import split_vevents_to_vcalendars
ics = (
"BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Google//EN\r\n"
"BEGIN:VEVENT\r\nUID:a@x\r\nSUMMARY:Reunion\r\nEND:VEVENT\r\n"
"BEGIN:VEVENT\r\nUID:b@x\r\nSUMMARY:Comida\r\nEND:VEVENT\r\n"
"END:VCALENDAR\r\n"
)
cals = split_vevents_to_vcalendars(ics)
print(len(cals)) # 2
print(cals[0].count("BEGIN:VEVENT")) # 1 (un evento por VCALENDAR)
Cuando usarla
Cuando exportas tu calendario de Google a un unico .ics (un VCALENDAR con
todos los eventos dentro) y necesitas subir cada evento como recurso CalDAV
separado a Xandikos. Es el primer paso del pipeline import_ics_to_caldav:
split → extraer UID por evento → caldav_put_event. Cada salida es un .ics
valido y autonomo que un cliente de calendario puede consumir por si solo.
Gotchas
Funcion pura. Replica TODAS las VTIMEZONE del VCALENDAR original en cada salida (conservador: garantiza que cualquier TZID referenciado por el VEVENT este definido, aunque algun evento no use ninguna). No deduplica ni filtra timezones por evento. No valida que el VEVENT este completo ni reescribe DTSTART /DTEND. Si el .ics no contiene VEVENT (p.ej. solo VTODO o VJOURNAL) devuelve lista vacia.