예제 #1
0
def load_credentials(config):
    """Loading and checking if credentials are valid

    :param config: Settings to load credentials.
    :type config: dict.
    :returns: list -- List of valid Twitter API credentials.
    """
    print '>> Loading credentials... '
    credentials_json = json.load(open(config["config_credentials_path"]))
    credentials = []
    credential = None
    for user in credentials_json:
        label = user.keys().pop()
        credential = AuthUser(label)
        credential.set_consumer_secret(user[label]["Consumer Secret (API Secret)"])
        credential.set_access_secret(user[label]["Access Token Secret"])
        credential.set_consumer_key(user[label]["Consumer Key (API Key)"])
        credential.set_access_token(user[label]["Access Token"])
        credential.do_session()
        try:
            data = credential.request(config["rate_limit_url"])
            if data is not False:
                if data["headers"]["status"] == '200':
                    credentials.append(credential)
                else:
                    print '>> Problem to load: '+credential._label
        except Exception, error:
            print error
            log.error(e, "Problem loading credential")
예제 #2
0
    def load_credentials(self):
        """
        Loading valid credentials for Twitter API

        :param config: Settings to load credentials.
        :type config: dict.
        :returns: list -- Valid API credentials or False, if none available.
        """
        print '>> Loading credentials... '
        config = self._config
        credentials_json = json.load(open(config["config_credentials_path"]))
        credentials = []
        credential = None
        for user in credentials_json:
            label = user.keys().pop()
            credential = AuthUser(label)
            credential.set_consumer_secret(user[label]["Consumer Secret (API Secret)"])
            credential.set_access_secret(user[label]["Access Token Secret"])
            credential.set_consumer_key(user[label]["Consumer Key (API Key)"])
            credential.set_access_token(user[label]["Access Token"])
            credential.do_session()
            try:
                data = credential.request(config["rate_limit_url"])
                if data is not False:
                    if data["headers"]["status"] == '200':
                        credentials.append(credential)
                    else:
                        print '!! Problem to load: ', label
            except Exception, error_log:
                print "!! Credential not loaded!!", error_log