termux-api
termux-api copied to clipboard
termux-contact-list in vcard format
Feature description termux-contact-list output in vcard format instead of json
and other fields than only name and phone
I second the request for other fields. And maybe have the number section as a list, as some people have multiple numbers (I added a test contact, only one number returned).
Anyways, you can parse the Json yourself and convert it to the VCARD format.
Python Code Example (Tested, works with current Json output. Will need to be adjusted if new fields are added):
import json
import subprocess
contacts = json.loads(subprocess.getoutput("termux-contact-list"))
#Contains working VCARD format
vcard = "\n".join([f"BEGIN:VCARD\nVERSION:2.1\nN:{';'.join(x['name'].split(' ')[::-1])}\nFN:{x['name']}\nTEL;CELL:{x['number']}\nEND:VCARD" for x in contacts])
python -c 'import json;import sys;print("\n".join([f"BEGIN:VCARD\nVERSION:4.0\nFN:{x["name"]}\nTEL;CELL:{x["number"]}\nEND:VCARD" for x in json.loads(sys.stdin.read())]))' <contacts.txt >contacts.vcf