mirror of
https://github.com/skoelle/icloud-contacts-sync.git
synced 2026-09-17 15:30:24 +00:00
related fix parser
This commit is contained in:
+28
-10
@@ -124,18 +124,36 @@ def parse_vcard(raw_text: str, account: str, etag: str | None = None) -> dict |
|
|||||||
|
|
||||||
categories = [c.strip() for c in vcard.categories.value] if hasattr(vcard, "categories") else []
|
categories = [c.strip() for c in vcard.categories.value] if hasattr(vcard, "categories") else []
|
||||||
|
|
||||||
|
_APPLE_LABEL_MAP = {
|
||||||
|
"father": "Vater", "mother": "Mutter", "parent": "Elternteil",
|
||||||
|
"son": "Sohn", "daughter": "Tochter", "child": "Kind",
|
||||||
|
"spouse": "Ehepartner", "wife": "Ehefrau", "husband": "Ehemann",
|
||||||
|
"partner": "Partner", "sibling": "Geschwister", "brother": "Bruder", "sister": "Schwester",
|
||||||
|
"friend": "Freund", "femalefriend": "Freundin", "malefriend": "Freund",
|
||||||
|
"colleague": "Kollege", "coworker": "Mitarbeiter",
|
||||||
|
"manager": "Vorgesetzter", "assistant": "Assistent",
|
||||||
|
"related": "Verwandter", "other": "Sonstige",
|
||||||
|
}
|
||||||
|
|
||||||
related_names = []
|
related_names = []
|
||||||
for r in vcard.contents.get("related", []):
|
abrelated = vcard.contents.get("x-abrelatednames", [])
|
||||||
params = getattr(r, "params", {})
|
ablabels = vcard.contents.get("x-ablabel", [])
|
||||||
type_val = params.get("TYPE") or params.get("type") or "other"
|
labels_by_group = {}
|
||||||
if isinstance(type_val, list):
|
for lbl in ablabels:
|
||||||
type_val = type_val[0] if type_val else "other"
|
labels_by_group[getattr(lbl, "group", "")] = lbl.value
|
||||||
value = r.value if r.value else ""
|
for r in abrelated:
|
||||||
if value.startswith(_MEMBER_PREFIX):
|
group = getattr(r, "group", "")
|
||||||
value = value[len(_MEMBER_PREFIX):]
|
raw_label = labels_by_group.get(group, "")
|
||||||
|
if raw_label.startswith("_$!<") and raw_label.endswith(">!$_"):
|
||||||
|
key = raw_label[4:-4].lower()
|
||||||
|
label = _APPLE_LABEL_MAP.get(key, key.capitalize())
|
||||||
|
elif raw_label:
|
||||||
|
label = raw_label
|
||||||
|
else:
|
||||||
|
label = "Sonstige"
|
||||||
related_names.append({
|
related_names.append({
|
||||||
"type": type_val,
|
"type": label,
|
||||||
"value": value,
|
"value": r.value if r.value else "",
|
||||||
})
|
})
|
||||||
|
|
||||||
photo_url = None
|
photo_url = None
|
||||||
|
|||||||
Reference in New Issue
Block a user