Exemplo n.º 1
0
def get_contacts(csv_file):
    #TODO: Allow adding to existing ContactBook.
    book = ContactBook()
    #TODO: Some special handling for phone numbers, emails, addresses to put the preferred one first.
    for row in read_csv(csv_file):
        contact = Contact()
        # Name
        if row.get('Name'):
            contact.name = row['Name']
        elif row.get('Organization 1 - Name'):
            contact.name = row['Organization 1 - Name']
        # Phone numbers
        parse_values(row,
                     contact,
                     'phones',
                     'Phone',
                     converter=Contact.normalize_phone)
        # Emails
        parse_values(row, contact, 'emails', 'E-mail')
        # Addresses
        parse_values(row,
                     contact,
                     'addresses',
                     'Address',
                     value_label='Formatted')
        # Organization
        parse_values(row,
                     contact,
                     'organizations',
                     'Organization',
                     value_label='Name')
        # Relationship
        # Note: There are instances where there's no Type, but there is a Value.
        # But currently no instances where there's a Value but no Type.
        parse_values(row, contact, 'relations', 'Relation')
        # Note
        if row.get('Note'):
            contact['notes'].add(row['Notes'])
        book.add(contact)
    return book