Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@my4paws
Created April 15, 2018 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save my4paws/ae7dc32ba9937996d4d13848ab13404c to your computer and use it in GitHub Desktop.
Save my4paws/ae7dc32ba9937996d4d13848ab13404c to your computer and use it in GitHub Desktop.
Pythonista add new contact to IOS
import contacts
import clipboard
import webbrowser
import dateutil
name = clipboard.get().split(',')
pers = contacts.Person()
grp = contacts.Group()
pers.first_name = name[0]
pers.last_name = name[1]
pers.middle_name = name[2]
pers.prefix = name[3]
pers.job_title = name[4]
pers.department = name[5]
pers.email = [(contacts.HOME, name[6])]
pers.address = [(contacts.HOME,
{contacts.STREET: name[7],
contacts.CITY: name[8],
contacts.STATE: name[9],
contacts.ZIP: name[10],
contacts.COUNTRY: name[11]})]
pers.nickname = name[13]
pers.organization = name[14]
pers.phone = [(contacts.HOME, name[15]),(contacts.IPHONE, name[16]),(contacts.WORK, name[17])]
from dateutil import parser
string_date = parser.parse(name[18])
pers.birthday = string_date
pers.url = [(contacts.HOMEPAGE, name[19])]
#here name[20] would provide the name of the group I want the contact to be added to
contacts.add_person(pers)
contacts.save()
webbrowser.open('workflow://')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment