#!/usr/bin/env python3

import csv
import subprocess

def add_contact(name, phone, email):
    cmd = ['termux-contact-add']
    if name:
        cmd.extend(['-n', name])
    if phone:
        cmd.extend(['-p', phone])
    if email:
        cmd.extend(['-e', email])
    
    if len(cmd) > 1:
        result = subprocess.run(cmd, capture_output=True, text=True)
        if result.returncode == 0:
            print(f"Added contact: {name}")
        else:
            print(f"Failed to add contact {name}: {result.stderr}")

def main():
    csv_file = 'shenzhen_69.csv'
    with open(csv_file, 'r') as f:
        reader = csv.DictReader(f)
        for row in reader:
            name = row.get('name', '')
            phone = row.get('phone', '')
            email = row.get('email', '')
            add_contact(name, phone, email)

if __name__ == '__main__':
    main()