Example #1
0
def invite_google(request):

    all_emails = []
    if 'token' in request.GET:

        token = request.GET['token']
        token_auth_login = AuthSubToken(token)
        
        query = ContactsQuery()
        query.max_results = MAX_RESULT

        client = ContactsClient(auth_token=token_auth_login)
        client.upgrade_token(token=token_auth_login)

        try:
            feed = client.GetContacts(q=query)
            while feed:
                next = feed.GetNextLink()

                for entry in feed.entry:
                    try:
                        email_address = entry.email[0].address
                        #print email_address
                        all_emails.append(email_address)
                    except:
                        pass

                feed = None
                if PAGING and next:
                    feed = client.GetContacts(next.href, auth_token=token_auth_login, q=query)
        except:
            pass

    return render(request , 'pin/invite_google.html', {'login': GetAuthSubUrl(), 'all_emails':all_emails})
Example #2
0
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 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 main():
    """
    main function
    """

    # API scope
    scope = 'https://www.google.com/m8/feeds/'

    client = client_contacts.ContactsClient(
        source='Carthage_College_DJUsagi_ContactsClient')

    # obtain our street cred
    credentials = get_cred(email, scope)
    # fetch our access token
    auth2token = OAuth2TokenFromCredentials(credentials)
    # authorize our client
    auth2token.authorize(client)

    # Note: The special userEmail value default can be used
    # to refer to the authenticated user.
    #earl = 'https://www.google.com/m8/feeds/contacts/default/full/'

    query = ContactsQuery()
    query.max_results = 10000

    contacts = client.GetContacts(q=query)

    for i, entry in enumerate(contacts.entry):
        try:
            print '\n%s %s' % (i + 1, entry.name.full_name.text)
        except:
            print '\n%s %s' % (i + 1, 'no full_name')
        if entry.content:
            print '    %s' % (entry.content.text)
        # Display the primary email address for the contact.
        for e in entry.email:
            if e.primary and e.primary == 'true':
                print '    %s' % (e.address)
        # Show the contact groups that this contact is a member of.
        for group in entry.group_membership_info:
            print '    Member of group: %s' % (group.href)
        # Display extended properties.
        for extended_property in entry.extended_property:
            if extended_property.value:
                value = extended_property.value
            else:
                value = extended_property.GetXmlBlob()
            print '    Extended Property - %s: %s' % (extended_property.name,
                                                      value)
Example #5
0
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/'
            ))
Example #6
0
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/'
        ))
Example #7
0
def invite_google(request):

    all_emails = []
    if 'token' in request.GET:

        token = request.GET['token']
        token_auth_login = AuthSubToken(token)

        query = ContactsQuery()
        query.max_results = MAX_RESULT

        client = ContactsClient(auth_token=token_auth_login)
        client.upgrade_token(token=token_auth_login)

        try:
            feed = client.GetContacts(q=query)
            while feed:
                next = feed.GetNextLink()

                for entry in feed.entry:
                    try:
                        email_address = entry.email[0].address
                        #print email_address
                        all_emails.append(email_address)
                    except:
                        pass

                feed = None
                if PAGING and next:
                    feed = client.GetContacts(next.href,
                                              auth_token=token_auth_login,
                                              q=query)
        except:
            pass

    return render(request, 'pin/invite_google.html', {
        'login': GetAuthSubUrl(),
        'all_emails': all_emails
    })
Example #8
0
 def get_contacts(self):
     query = ContactsQuery(max_results=10)
     return self._contacts_client.GetContacts(q=query)
Example #9
0
    def contacts(self, max_results):

        query = ContactsQuery()
        query.max_results = max_results

        return self.client.GetContacts(q = query)
Example #10
0
 def fetch_contacts(self):
     client = self.__get_client()
     query = ContactsQuery(max_results=self.config.max_results)
     entries = client.get_contacts(query=query).entry
     return dict([self.__parse_contact(ent) for ent in entries])