scripts/get_users_emails.py
def login(self, username='', password=''):
        """
        Performs a login and sets the Github object via given credentials. If
        credentials are empty or incorrect then prompts user for credentials.
        Stores the authentication token in a CREDENTIALS_FILE used for future
        logins. Handles Two Factor Authentication.
        """
        try:

            token = ''
            id = ''
            if not os.path.isfile('CREDENTIALS_FILE'):
                if(username == '' or password == ''):
                    username = raw_input('Username: ')
                    password = getpass.getpass('Password: ')
                note = 'GitHub Organization Stats App'
                note_url = 'http://software.llnl.gov/'
                scopes = ['user', 'repo']
                auth = github3.authorize(username, password, scopes, note,
                    note_url, two_factor_callback=self.prompt_2fa)
                token = auth.token
                id = auth.id
                with open('CREDENTIALS_FILE', 'w+') as fd:
                    fd.write(token + '\n')
                    fd.write(str(id))
                fd.close()
            else:
                with open('CREDENTIALS_FILE', 'r') as fd:
                    token = fd.readline().strip()
                    id = fd.readline().strip()
                fd.close()
            print "Logging in."
            self.logged_in_gh = github3.login(token=token, two_factor_callback=self.prompt_2fa)
            self.logged_in_gh.user().to_json()
        except (ValueError, AttributeError, github3.models.GitHubError) as e:
            print 'Bad credentials. Try again.'
            self.login()
def login(self, username='', password=''):
        """
        Performs a login and sets the Github object via given credentials. If
        credentials are empty or incorrect then prompts user for credentials.
        Stores the authentication token in a CREDENTIALS_FILE used for future
        logins. Handles Two Factor Authentication.
        """
        try:

            token = ''
            id = ''
            if not os.path.isfile('CREDENTIALS_FILE'):
                if(username == '' or password == ''):
                    username = raw_input('Username: ')
                    password = getpass.getpass('Password: ')
                note = 'GitHub Organization Stats App'
                note_url = 'http://software.llnl.gov/'
                scopes = ['user', 'repo']
                auth = github3.authorize(username, password, scopes, note,
                    note_url, two_factor_callback=self.prompt_2fa)
                token = auth.token
                id = auth.id
                with open('CREDENTIALS_FILE', 'w+') as fd:
                    fd.write(token + '\n')
                    fd.write(str(id))
                fd.close()
            else:
                with open('CREDENTIALS_FILE', 'r') as fd:
                    token = fd.readline().strip()
                    id = fd.readline().strip()
                fd.close()
            print "Logging in."
            self.logged_in_gh = github3.login(token=token, two_factor_callback=self.prompt_2fa)
            self.logged_in_gh.user().to_json()
        except (ValueError, AttributeError, github3.models.GitHubError) as e:
            print 'Bad credentials. Try again.'
            self.login()
Performs a login and sets the Github object via given credentials. If
        credentials are empty or incorrect then prompts user for credentials.
        Stores the authentication token in a CREDENTIALS_FILE used for future
        logins. Handles Two Factor Authentication.