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")
def get_last_status(_list, txt_path): """ :param _list: list of status :txt_path: path for file with last status to be found in _list :returns: index position of the element in the file, 0 if not found """ i = 0 try: last = linecache.getline(txt_path, 1).rstrip("\n") for item in _list: if last.rstrip("\n") in item: return i i = i + 1 except IOError: _log.error("File not found, returning position 0 for "+txt_path) return 0