View Single Post
nicolai's Avatar
Posts: 1,637 | Thanked: 4,404 times | Joined on Apr 2009 @ Germany
#15
Quick Python script

PHP Code:
import evolution
import sys

from optparse import OptionParser

def search_contact
(options):
    
ebook evolution.ebook.open_addressbook("default")
    if 
not options.contact is None:
        
contacts ebook.search(options.contact)
    
elif not options.full_name is None:
        
contacts = []
        for 
c in ebook.get_all_contacts():
            if 
c.get_name() == options.full_name:
                
contacts.append(c)
    
elif not options.nick_name is None:
        
contacts = []
        for 
c in ebook.get_all_contacts():
            if 
c.get_property("nickname") == options.nick_name:
                
contacts.append(c)
    
    if (
not options.attributes is None) and (len(options.attributes) > 0):
        for 
contact in contacts:
            print 
contact.get_property("full-name")
            for 
a in options.attributes:
                print 
contact.get_property(a)
    if 
options.list:
        for 
contact in contacts:
            for 
p in contact.props:
                
value contact.get_property(p.name)
                if 
not value is None
                    print 
p.namevalue

    
if options.export:
        for 
contact in contacts:
            print 
contact.get_vcard_string()

def main():
    
parser OptionParser()
    
parser.add_option("-c""--contact"help="contact name to search for"action="store"type="string"dest="contact")
    
parser.add_option("-f""--full-name"help="select contact with this name"action="store"type="string"dest="full_name")
    
parser.add_option("-n""--nickname"help="select contact with this nickname"action="store"type="string"dest="nick_name")
    
parser.add_option("-a""--attribute"help="contact attributes -a attribute1 -a attribute2 .."action="append"type="string"dest="attributes")
    
parser.add_option("-e""--export"help="print vcard string"action="store_true"dest="export", default=False)
    
parser.add_option("-l""--list-attributes"help="list vcard attributes"action="store_true"dest="list", default=False)
    
    (
optionsargs) = parser.parse_args(sys.argv)
    
    if 
len(sys.argv) <= 1:
        
parser.print_help()
    else:
        
search_contact(options)

if 
__name__ == "__main__":
    
main() 

Last edited by nicolai; 04-17-2011 at 05:13 PM.
 

The Following 7 Users Say Thank You to nicolai For This Useful Post: