def get_group_members(contacts_client, group): if not group: return [] contacts_query = ContactsQuery() contacts_query.group = group.id.text contacts_query.max_results = options().max_contacts return contacts_client.get_contacts(q=contacts_query).entry
def import_google_contacts(): try: api = google.create_api(google.ContactsClient) group_id = None feed = api.GetGroups() for entry in feed.entry: if entry.title.text == 'System Group: My Contacts': group_id = entry.id.text query = ContactsQuery() query.max_results = 10000 if group_id: query.group = group_id feed = api.GetContacts(q=query) my_emails = current_user.emails for entry in feed.entry: with db.transaction as session: for email in entry.email: if not entry.name or not entry.name.full_name: continue contact = current_user.find_email_contact(email.address) if not contact: contact = create_email_contact(email.address) contact.name = entry.name.full_name.text contact.email = email.address contact.user = current_user contact.belongs_to_user = email.address in my_emails session.add(contact) else: contact.name = entry.name.full_name.text return redirect(url_for('contacts')) except (google.ConnectionError, google.UnauthorizedError): return redirect( google.create_authorize_url( action_url=url_for('import_google_contacts'), error_url=url_for('contacts'), scope= 'https://www.google.com/calendar/feeds/ https://www.google.com/m8/feeds/' ))
def import_google_contacts(): try: api = google.create_api(google.ContactsClient) group_id = None feed = api.GetGroups() for entry in feed.entry: if entry.title.text == 'System Group: My Contacts': group_id = entry.id.text query = ContactsQuery() query.max_results = 10000 if group_id: query.group = group_id feed = api.GetContacts(q=query) my_emails = current_user.emails for entry in feed.entry: with db.transaction as session: for email in entry.email: if not entry.name or not entry.name.full_name: continue contact = current_user.find_email_contact(email.address) if not contact: contact = create_email_contact(email.address) contact.name = entry.name.full_name.text contact.email = email.address contact.user = current_user contact.belongs_to_user = email.address in my_emails session.add(contact) else: contact.name = entry.name.full_name.text return redirect(url_for('contacts')) except (google.ConnectionError, google.UnauthorizedError): return redirect(google.create_authorize_url( action_url=url_for('import_google_contacts'), error_url=url_for('contacts'), scope='https://www.google.com/calendar/feeds/ https://www.google.com/m8/feeds/' ))