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):
88 def get_addressbooks(self):
90 @returns Iterable of (Address Book Factory, Book Id, Book Name)
94 feed = self._client.GetGroupsFeed()
97 name = entry.title.text
99 yield self, "all", "All"
101 def open_addressbook(self, bookId):
105 return GDataAddressBook(self._client)
107 return GDataAddressBook(self._client, bookId)
114 def print_gbooks(username, password):
116 Included here for debugging.
118 Either insert it into the code or launch python with the "-i" flag
120 abf = GDataAddressBookFactory(username, password)
121 for book in abf.get_addressbooks():
122 ab = abf.open_addressbook(book[1])
124 for contact in ab.get_contacts():
126 for details in ab.get_contact_details(contact[0]):
127 print "\t\t", details