コード例 #1
0
    def likes(self, type=None, **kwargs):
        if type and type not in ['comments', 'lists']:
            raise ValueError('Unknown type specified: %r' % type)

        if kwargs.get('parse') is False:
            raise ValueError('Parse can\'t be disabled on this method')

        # Send request
        response = self.http.get(
            'likes',
            params=[type],
            **popitems(kwargs, ['authenticated', 'validate_token']))

        # Parse response
        items = self.get_data(response, **kwargs)

        if not items:
            return

        # Map items to comment/list objects
        for item in items:
            item_type = item.get('type')

            if item_type == 'comment':
                yield CommentMapper.comment(self.client, item)
            elif item_type == 'list':
                yield ListMapper.custom_list(self.client, item)
            else:
                log.warn('Unknown item returned, type: %r', item_type)
コード例 #2
0
ファイル: __init__.py プロジェクト: viniciusbig/trakt.py
    def get(self, username, **kwargs):
        """Retrieve lists for user.

        :param username: Username (or :code:`me`)
        :type username: :class:`~python:str`

        :return: List
        :rtype: trakt.objects.CustomList
        """
        if kwargs.get('parse') is False:
            raise ValueError("Parse can't be disabled on this method")

        # Send request
        response = self.http.get('/users/%s/lists' %
                                 clean_username(username), )

        # Parse response
        items = self.get_data(response, **kwargs)

        if not items:
            return

        # Map items to list objects
        for item in items:
            yield ListMapper.custom_list(self.client, item, username=username)
コード例 #3
0
    def likes(self, type=None, **kwargs):
        if type and type not in ['comments', 'lists']:
            raise ValueError('Unknown type specified: %r' % type)

        # Send request
        response = self.http.get('likes', params=[
            type
        ])

        if response.status_code < 200 or response.status_code >= 300:
            return

        # Parse response
        items = self.get_data(response, **kwargs)

        # Map items to comment/list objects
        for item in items:
            item_type = item.get('type')

            if item_type == 'comment':
                yield CommentMapper.comment(
                    self.client, item
                )
            elif item_type == 'list':
                yield ListMapper.custom_list(
                    self.client, item
                )
            else:
                log.warn('Unknown item returned, type: %r', item_type)
コード例 #4
0
ファイル: __init__.py プロジェクト: fergyc/tknorris-beta-repo
    def create(self,
               username,
               name,
               description=None,
               privacy='private',
               display_numbers=False,
               allow_comments=True,
               **kwargs):
        data = {
            'name': name,
            'description': description,
            'privacy': privacy,
            'allow_comments': allow_comments,
            'display_numbers': display_numbers
        }

        # Remove attributes with `None` values
        for key in list(data.keys()):
            if data[key] is not None:
                continue

            del data[key]

        # Send request
        response = self.http.post('/users/%s/lists' % username, data=data)

        if response.status_code < 200 or response.status_code >= 300:
            return None

        # Parse response
        item = self.get_data(response)

        # Map item to list object
        return ListMapper.custom_list(self.client, item, username=username)
コード例 #5
0
ファイル: __init__.py プロジェクト: AMOboxTV/AMOBox.LegoBuild
    def create(self, username, name, description=None, privacy='private',
               display_numbers=False, allow_comments=True, **kwargs):
        data = {
            'name': name,
            'description': description,

            'privacy': privacy,
            'allow_comments': allow_comments,
            'display_numbers': display_numbers
        }

        # Remove attributes with `None` values
        for key in list(data.keys()):
            if data[key] is not None:
                continue

            del data[key]

        # Send request
        response = self.http.post(
            '/users/%s/lists' % username,
            data=data
        )

        if response.status_code < 200 or response.status_code >= 300:
            return None

        # Parse response
        item = self.get_data(response)

        # Map item to list object
        return ListMapper.custom_list(
            self.client, item,
            username=username
        )
コード例 #6
0
    def likes(self, type=None):
        if type and type not in ['comments', 'lists']:
            raise ValueError('Unknown type specified: %r', type)

        # Send request
        response = self.http.get('likes', params=[
            type
        ])

        if response.status_code < 200 or response.status_code >= 300:
            return

        # Parse response
        items = self.get_data(response)

        # Map items to comment/list objects
        for item in items:
            item_type = item.get('type')

            if item_type == 'comment':
                yield CommentMapper.comment(
                    self.client, item
                )
            elif item_type == 'list':
                yield ListMapper.custom_list(
                    self.client, item
                )
            else:
                log.warn('Unknown item returned, type: %r', item_type)
コード例 #7
0
    def _map(self, item):
        item_type = item.get('type')

        if item_type == 'comment':
            return CommentMapper.comment(self.client, item)

        if item_type == 'list':
            return ListMapper.custom_list(self.client, item)

        log.warning('Unknown item returned, type: %r', item_type)
        return None
コード例 #8
0
ファイル: list_.py プロジェクト: martisj/traktforalfred
    def get(self, username, id):
        response = self.http.get('/users/%s/lists/%s' % (username, id), )

        if response.status_code < 200 or response.status_code >= 300:
            return None

        # Parse response
        item = self.get_data(response)

        # Map item to list object
        return ListMapper.custom_list(self.client, item, username=username)
コード例 #9
0
ファイル: __init__.py プロジェクト: viniciusbig/trakt.py
    def trending(self, page=None, per_page=None, **kwargs):
        response = self.http.get('trending',
                                 query={
                                     'page': page,
                                     'limit': per_page
                                 },
                                 **dictfilter(kwargs,
                                              get=['exceptions'],
                                              pop=['pagination']))

        # Parse response
        items = self.get_data(response, **kwargs)

        if isinstance(items, PaginationIterator):
            return items.with_mapper(
                lambda items: ListMapper.public_lists(self.client, items))

        if isinstance(items, requests.Response):
            return items

        return ListMapper.public_lists(self.client, items)
コード例 #10
0
ファイル: __init__.py プロジェクト: fergyc/tknorris-beta-repo
    def get(self, username, **kwargs):
        # Send request
        response = self.http.get('/users/%s/lists' % username, )

        if response.status_code < 200 or response.status_code >= 300:
            return

        # Parse response
        items = self.get_data(response)

        # Map items to list objects
        for item in items:
            yield ListMapper.custom_list(self.client, item, username=username)
コード例 #11
0
    def update(self,
               username,
               id,
               name=None,
               description=None,
               privacy=None,
               display_numbers=None,
               allow_comments=None,
               return_type='object',
               **kwargs):
        data = {
            'name': name,
            'description': description,
            'privacy': privacy,
            'allow_comments': allow_comments,
            'display_numbers': display_numbers
        }

        # Remove attributes with `None` values
        for key in list(data.keys()):
            if data[key] is not None:
                continue

            del data[key]

        # Send request
        response = self.http.put(
            '/users/%s/lists/%s' % (clean_username(username), id),
            data=data,
            **popitems(kwargs, ['authenticated', 'validate_token']))

        # Parse response
        item = self.get_data(response, **kwargs)

        if isinstance(item, requests.Response):
            return item

        if not item:
            return None

        if return_type == 'data':
            return item

        if return_type == 'object':
            # Map item to list object
            return ListMapper.custom_list(self.client, item, username=username)

        raise ValueError('Unsupported value for "return_type": %r',
                         return_type)
コード例 #12
0
ファイル: list_.py プロジェクト: fuzeman/Plex-Trakt-Scrobbler
    def update(self, username, id, name=None, description=None, privacy=None, display_numbers=None,
               allow_comments=None, return_type='object', **kwargs):
        data = {
            'name': name,
            'description': description,

            'privacy': privacy,
            'allow_comments': allow_comments,
            'display_numbers': display_numbers
        }

        # Remove attributes with `None` values
        for key in list(data.keys()):
            if data[key] is not None:
                continue

            del data[key]

        # Send request
        response = self.http.put(
            '/users/%s/lists/%s' % (clean_username(username), id),
            data=data,
            **popitems(kwargs, [
                'authenticated',
                'validate_token'
            ])
        )

        # Parse response
        item = self.get_data(response, **kwargs)

        if isinstance(item, requests.Response):
            return item

        if not item:
            return None

        if return_type == 'data':
            return item

        if return_type == 'object':
            # Map item to list object
            return ListMapper.custom_list(
                self.client, item,
                username=username
            )

        raise ValueError("Unsupported value for \"return_type\": %r", return_type)
コード例 #13
0
    def get(self, username, id, **kwargs):
        # Send request
        response = self.http.get(
            '/users/%s/lists/%s' % (clean_username(username), id), )

        # Parse response
        item = self.get_data(response, **kwargs)

        if isinstance(item, requests.Response):
            return item

        if not item:
            return None

        # Map item to list object
        return ListMapper.custom_list(self.client, item, username=username)
コード例 #14
0
ファイル: list_.py プロジェクト: AMOboxTV/AMOBox.LegoBuild
    def get(self, username, id):
        response = self.http.get(
            '/users/%s/lists/%s' % (username, id),
        )

        if response.status_code < 200 or response.status_code >= 300:
            return None

        # Parse response
        item = self.get_data(response)

        # Map item to list object
        return ListMapper.custom_list(
            self.client, item,
            username=username
        )
コード例 #15
0
    def get(self, username, **kwargs):
        if kwargs.get('parse') is False:
            raise ValueError('Parse can\'t be disabled on this method')

        # Send request
        response = self.http.get('/users/%s/lists' %
                                 clean_username(username), )

        # Parse response
        items = self.get_data(response, **kwargs)

        if not items:
            return

        # Map items to list objects
        for item in items:
            yield ListMapper.custom_list(self.client, item, username=username)
コード例 #16
0
    def update(self,
               username,
               id,
               name=None,
               description=None,
               privacy=None,
               display_numbers=None,
               allow_comments=None,
               return_type='object',
               **kwargs):
        data = {
            'name': name,
            'description': description,
            'privacy': privacy,
            'allow_comments': allow_comments,
            'display_numbers': display_numbers
        }

        # Remove attributes with `None` values
        for key in list(data.keys()):
            if data[key] is not None:
                continue

            del data[key]

        # Send request
        response = self.http.put('/users/%s/lists/%s' %
                                 (clean_username(username), id),
                                 data=data)

        if response.status_code < 200 or response.status_code >= 300:
            return None

        # Parse response
        item = self.get_data(response)

        if return_type == 'data':
            return item

        if return_type == 'object':
            # Map item to list object
            return ListMapper.custom_list(self.client, item, username=username)

        raise ValueError("Unsupported value for \"return_type\": %r",
                         return_type)
コード例 #17
0
ファイル: __init__.py プロジェクト: AMOboxTV/AMOBox.LegoBuild
    def get(self, username, **kwargs):
        # Send request
        response = self.http.get(
            '/users/%s/lists' % username,
        )

        if response.status_code < 200 or response.status_code >= 300:
            return

        # Parse response
        items = self.get_data(response)

        # Map items to list objects
        for item in items:
            yield ListMapper.custom_list(
                self.client, item,
                username=username
            )
コード例 #18
0
ファイル: list_.py プロジェクト: fuzeman/Plex-Trakt-Scrobbler
    def get(self, username, id, **kwargs):
        # Send request
        response = self.http.get(
            '/users/%s/lists/%s' % (clean_username(username), id),
        )

        # Parse response
        item = self.get_data(response, **kwargs)

        if isinstance(item, requests.Response):
            return item

        if not item:
            return None

        # Map item to list object
        return ListMapper.custom_list(
            self.client, item,
            username=username
        )
コード例 #19
0
ファイル: list_.py プロジェクト: AMOboxTV/AMOBox.LegoBuild
    def update(self, username, id, name=None, description=None, privacy=None, display_numbers=None,
               allow_comments=None, return_type='object', **kwargs):
        data = {
            'name': name,
            'description': description,

            'privacy': privacy,
            'allow_comments': allow_comments,
            'display_numbers': display_numbers
        }

        # Remove attributes with `None` values
        for key in list(data.keys()):
            if data[key] is not None:
                continue

            del data[key]

        # Send request
        response = self.http.put(
            '/users/%s/lists/%s' % (username, id),
            data=data
        )

        if response.status_code < 200 or response.status_code >= 300:
            return None

        # Parse response
        item = self.get_data(response)

        if return_type == 'data':
            return item

        if return_type == 'object':
            # Map item to list object
            return ListMapper.custom_list(
                self.client, item,
                username=username
            )

        raise ValueError("Unsupported value for \"return_type\": %r", return_type)
コード例 #20
0
    def get(self, username, **kwargs):
        if kwargs.get('parse') is False:
            raise ValueError('Parse can\'t be disabled on this method')

        # Send request
        response = self.http.get(
            '/users/%s/lists' % clean_username(username),
        )

        # Parse response
        items = self.get_data(response, **kwargs)

        if not items:
            return

        # Map items to list objects
        for item in items:
            yield ListMapper.custom_list(
                self.client, item,
                username=username
            )
コード例 #21
0
ファイル: __init__.py プロジェクト: SiCKRAGETV/SiCKRAGE
    def likes(self, type=None, **kwargs):
        if type and type not in ['comments', 'lists']:
            raise ValueError('Unknown type specified: %r' % type)

        if kwargs.get('parse') is False:
            raise ValueError('Parse can\'t be disabled on this method')

        # Send request
        response = self.http.get(
            'likes',
            params=[type],
            **popitems(kwargs, [
                'authenticated',
                'validate_token'
            ])
        )

        # Parse response
        items = self.get_data(response, **kwargs)

        if not items:
            return

        # Map items to comment/list objects
        for item in items:
            item_type = item.get('type')

            if item_type == 'comment':
                yield CommentMapper.comment(
                    self.client, item
                )
            elif item_type == 'list':
                yield ListMapper.custom_list(
                    self.client, item
                )
            else:
                log.warn('Unknown item returned, type: %r', item_type)
コード例 #22
0
ファイル: __init__.py プロジェクト: viniciusbig/trakt.py
    def create(self,
               username,
               name,
               description=None,
               privacy='private',
               display_numbers=False,
               allow_comments=True,
               sort_by='rank',
               sort_how='asc',
               **kwargs):
        """Create a new list.

        :param username: Username (or :code:`me`)
        :type username: :class:`~python:str`

        :param name: Name
        :type name: :class:`~python:str`

        :param description: Description
        :type description: :class:`~python:str`

        :param privacy: Privacy (:code:`private`, :code:`friends`, or :code:`public`)
        :type description: :class:`~python:str`

        :param display_numbers: Flag indicating this list displays numbers
        :type description: :class:`~python:bool`

        :param allow_comments: Flag indicating this list allows comments
        :type description: :class:`~python:bool`

        :param sort_by: Sort By (:code:`rank`, :code:`added`, :code:`title`, :code:`released`,
                        :code:`runtime`, :code:`popularity`, :code:`percentage`, :code:`votes`,
                        :code:`my_rating`, :code:`random`, :code:`watched`, :code:`collected`)
        :type sort_by: :class:`~python:str`

        :param sort_how: Sort Direction (:code:`asc`, or :code:`desc`)
        :type sort_how: :class:`~python:str`

        :return: List
        :rtype: trakt.objects.CustomList
        """
        data = {
            'name': name,
            'description': description,
            'privacy': privacy,
            'allow_comments': allow_comments,
            'display_numbers': display_numbers,
            'sort_by': sort_by,
            'sort_how': sort_how
        }

        # Remove attributes with `None` values
        for key in list(data.keys()):
            if data[key] is not None:
                continue

            del data[key]

        # Send request
        response = self.http.post('/users/%s/lists' % clean_username(username),
                                  data=data)

        # Parse response
        item = self.get_data(response, **kwargs)

        if isinstance(item, requests.Response):
            return item

        if not item:
            return None

        # Map item to list object
        return ListMapper.custom_list(self.client, item, username=username)