def test_notify(username, blacklist_name=None): """Send a test notification to trakt with the given authentication info and returns a boolean. api: The api string to use username: The username to use blacklist_name: slug of trakt list used to hide not interested show Returns: True if the request succeeded, False otherwise """ try: trakt_settings = { 'trakt_api_secret': app.TRAKT_API_SECRET, 'trakt_api_key': app.TRAKT_API_KEY, 'trakt_access_token': app.TRAKT_ACCESS_TOKEN, 'trakt_refresh_token': app.TRAKT_REFRESH_TOKEN } trakt_api = TraktApi(app.SSL_VERIFY, app.TRAKT_TIMEOUT, **trakt_settings) trakt_api.validate_account() if blacklist_name and blacklist_name is not None: trakt_lists = trakt_api.request('users/' + username + '/lists') found = False for trakt_list in trakt_lists: if trakt_list['ids']['slug'] == blacklist_name: return 'Test notice sent successfully to Trakt' if not found: return "Trakt blacklist doesn't exists" else: return 'Test notice sent successfully to Trakt' except (TokenExpiredException, TraktException, AuthException) as error: log.warning('Unable to test TRAKT: {0}', error.message) return 'Test notice failed to Trakt: {0}'.format(error.message)
def test_notify(username, blacklist_name=None): """ Sends a test notification to trakt with the given authentication info and returns a boolean representing success. api: The api string to use username: The username to use blacklist_name: slug of trakt list used to hide not interested show Returns: True if the request succeeded, False otherwise """ try: trakt_settings = {'trakt_api_secret': app.TRAKT_API_SECRET, 'trakt_api_key': app.TRAKT_API_KEY, 'trakt_access_token': app.TRAKT_ACCESS_TOKEN} trakt_api = TraktApi(app.SSL_VERIFY, app.TRAKT_TIMEOUT, **trakt_settings) trakt_api.validate_account() if blacklist_name and blacklist_name is not None: trakt_lists = trakt_api.request('users/' + username + '/lists') found = False for trakt_list in trakt_lists: if trakt_list['ids']['slug'] == blacklist_name: return 'Test notice sent successfully to Trakt' if not found: return "Trakt blacklist doesn't exists" else: return 'Test notice sent successfully to Trakt' except (TraktException, AuthException, ServerBusy) as trakt_ex: logger.log('Could not connect to Trakt service: {0}'.format(ex(trakt_ex)), logger.WARNING) return 'Test notice failed to Trakt: {0}'.format(ex(trakt_ex))