configuration/local/bin/vcard-simplify.py

55 lines
1.3 KiB
Python
Raw Normal View History

2024-07-24 08:35:41 +02:00
#!/usr/bin/env python
import sys
def copy(line):
print(line, end="")
def output(key, value):
print(key, value, sep=":", end="\r\n")
for line in sys.stdin:
key, *value = line.strip().split(":")
value = ":".join(value)
if key == "BEGIN" and value == "VCARD":
copy(line)
elif key == "VERSION":
output("VERSION", "2.1")
elif key == "N":
copy(line)
elif key == "FN":
copy(line)
elif key == "ORG":
pass
elif (key == "EMAIL;TYPE=INTERNET;TYPE=WORK" or
key == "EMAIL;TYPE=INTERNET;TYPE=HOME" or
key == "EMAIL;TYPE=INTERNET;TYPE=OTHER"):
output("EMAIL;X-internet", value)
elif (key == "TEL;TYPE=VOICE" or
key == "TEL;TYPE=CELL" or
key == "TEL;TYPE=WORK" or
key == "TEL;TYPE=HOME" or
key == "TEL;TYPE=OTHER"):
if value.startswith("tel:"):
value = value[4:]
output("TEL;VOICE", value.replace(" ", ""))
elif key == "TEL;TYPE=PAGER":
pass
elif (key == "ADR;TYPE=HOME" or key == "ADR;TYPE=OTHER"):
output("ADR;HOME", value)
elif key == "CATEGORIES":
pass
elif key == "NICKNAME":
pass
elif key.startswith("URL"):
pass
elif key == "BDAY;VALUE=date":
pass
elif key.startswith("NOTE"):
pass
elif key.startswith("TITLE"):
pass
elif key == "END" and value == "VCARD":
copy(line)
else:
raise NotImplementedError(line)