4 sys.path.insert(0,"../gdata/src/")
11 except (ImportError, AttributeError):
16 class GDataAddressBook(object):
20 def __init__(self, client, id = None):
25 def clear_caches(self):
33 def contact_source_short_name(contactId):
36 def get_contacts(self):
38 @returns Iterable of (contact id, contact name)
42 def get_contact_details(self, contactId):
44 @returns Iterable of (Phone Type, Phone Number)
48 def _get_contacts(self):
49 if len(self._contacts) != 0:
51 feed = self._get_feed()
53 name = entry.title.text
55 for extendedProperty in entry.extended_property:
56 if extendedProperty.value:
57 print extendedProperty.value
59 print extendedProperty.GetXmlBlobString()
63 return self._client.GetContactsFeed()
68 class GDataAddressBookFactory(object):
70 def __init__(self, username, password):
71 self._username = username
72 self._password = password
77 self._client = gdata.contacts.service.ContactsService()
78 self._client.email = username
79 self._client.password = password
80 self._client.source = "DialCentra"
81 self._client.ProgrammaticLogin()
83 def clear_caches(self):
87 def get_addressbooks(self):
89 @returns Iterable of (Address Book Factory, Book Id, Book Name)
93 feed = self._client.GetGroupsFeed()
96 name = entry.title.text
98 yield self, "all", "All"
100 def open_addressbook(self, bookId):
104 return GDataAddressBook(self._client)
106 return GDataAddressBook(self._client, bookId)
113 def print_gbooks(username, password):
115 Included here for debugging.
117 Either insert it into the code or launch python with the "-i" flag
119 abf = GDataAddressBookFactory(username, password)
120 for book in abf.get_addressbooks():
121 ab = abf.open_addressbook(book[1])
123 for contact in ab.get_contacts():
125 for details in ab.get_contact_details(contact[0]):
126 print "\t\t", details