Back up Your Contacts with Pythonista

Posted on 2014-09-28

While it hasn't happened in a while, I have lost or had issues with contacts in iCloud. I haven't found a reliable way to automatically back up my contacts on my Mac, but Pythonista offers a simple way to back them up.

Pythonista offers a great library which gives you access to your contacts on iOS. With a short script, I can back up my contacts to a folder in my Dropbox account. This will add a vCard file to my Dropbox account with the date the script was run.

Note: You'll need the Dropbox login script for this to work. Visit this link to get it set up. I keep mine in a folder called "lib" in Pythonista.

You can download my Contacts Back up script here.

import contacts
import sys, os
import console
sys.path += [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib')]
from dropboxlogin import get_client
from datetime import datetime

# Update this path here for the backup
# location in your Dropbox account.
BACKUP_PATH = '/Backups/Contacts'

TODAY = datetime.today().strftime('%Y-%m-%d')

dropbox_client = get_client()

VCARD = "".join(person.vcard for person in contacts.get_all_people())

console.clear()
dropbox_client.put_file(BACKUP_PATH + '/contacts {}.vcf'.format(TODAY), VCARD)
print 'Backup complete!'

If you're like me, you're going to forget to do this on a regular basis. I hadn't yet found a reason to use the IFTTT Launch Center Pro triggers, but this turned about to be a great reason to use it. I have a trigger that goes off on the first of every month that will launch the back up script.

If you want to get reminders to back up your contacts using IFTTT, you can use the recipe below.

IFTTT Recipe: Backup Contacts with LCP connects date-time to launch-center

Tags: automation Dropbox ifttt launchcenterpro ios pythonista

back-up-your-contacts-with-pythonista

© Ryan M 2023. Built using Pelican.