termux-api icon indicating copy to clipboard operation
termux-api copied to clipboard

termux-contact-list in vcard format

Open KrullBorg opened this issue 6 years ago • 2 comments

Feature description termux-contact-list output in vcard format instead of json

and other fields than only name and phone

KrullBorg avatar Nov 16 '19 21:11 KrullBorg

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])

AbdullahM0hamed avatar Dec 07 '19 00:12 AbdullahM0hamed

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

jankratochvil avatar Dec 29 '24 04:12 jankratochvil