<commit_before># coding: utf-8

"""
:mod:`boardgamegeek.hotitems` - BoardGameGeek "Hot Items"
=========================================================

.. module:: boardgamegeek.hotitems
   :platform: Unix, Windows
   :synopsis: BGG "Hot Items"

.. moduleauthor:: <NAME> <<EMAIL>>
"""
from __future__ import unicode_literals

from copy import copy

from .exceptions import BoardGameGeekError
from .things import Thing
from .utils import DictObject


class HotItem(Thing):
    """
    A hot item from a list. Can refer to either an item (``boardgame``, ``videogame``, etc.), a person (``rpgperson``,
    ``boardgameperson``) or even a company (``boardgamecompany``, ``videogamecompany``), depending on the type of hot
    list retrieved.
    """

    def __init__(self, data):
        if "rank" not in data:
            raise BoardGameGeekError("missing rank of HotItem")

        super(HotItem, self).__init__(data)

    def __repr__(self):
        return "HotItem (id: {})".format(self.id)

    def _format(self, log):
        log.info("hot item id        : {}".format(self.id))
        log.info("hot item name      : {}".format(self.name))
        log.info("hot item rank      : {}".format(self.rank))
        log.info("hot item published : {}".format(self.year))
        log.info("hot item thumbnail : {}".format(self.thumbnail))

    @property
    def rank(self):
        """
        :return: Ranking of this hot item
        """
        return self._data["rank"]

    @property
    def year(self):
        """
        Year this item was published

        :return: integer representing the year
        :return: ``None`` if object doesn't refer to a game
        """
        return self._data.get("yearpublished")

    @property
    def thumbnail(self):
        """
        :return: url of the thumbnail corresponding to this item
        """
        return self._data.get("thumbnail")


class HotItems(DictObject):
    """
    A container for :class:`boardgamegeek.hotitems.HotItem`
    """
    def __init__(self, data):
        kw = copy(data)
        if "items" not in kw:
            kw["items"] = []

        self._items = []
        for data in kw["items"]:
            self._items.append(HotItem(data))

        super(HotItems, self).__init__(kw)

    def add_hot_item(self, data):
        """
        Add a new hot item to the container

        :param data: dictionary containing the data

        """
        self._data["items"].append(data)
        self._items.append(HotItem(data))

    @property
    def items(self):
        """

        :return: the list of :class:`boardgamegeek.hotitems.HotItem`
        """
        return self._items

    def __len__(self):
        return len(self._items)

    def __iter__(self):
        for item in self._data["items"]:
            yield HotItem(item)

    def __getitem__(self, item):
        return self._items.__getitem__(item)<commit_msg>Fixed thumbnail urls for hot items<commit_after># coding: utf-8

"""
:mod:`boardgamegeek.hotitems` - BoardGameGeek "Hot Items"
=========================================================

.. module:: boardgamegeek.hotitems
   :platform: Unix, Windows
   :synopsis: BGG "Hot Items"

.. moduleauthor:: <NAME> <<EMAIL>>
"""
from __future__ import unicode_literals

from copy import copy

from .exceptions import BoardGameGeekError
from .things import Thing
from .utils import DictObject, fix_url


class HotItem(Thing):
    """
    A hot item from a list. Can refer to either an item (``boardgame``, ``videogame``, etc.), a person (``rpgperson``,
    ``boardgameperson``) or even a company (``boardgamecompany``, ``videogamecompany``), depending on the type of hot
    list retrieved.
    """

    def __init__(self, data):
        if "rank" not in data:
            raise BoardGameGeekError("missing rank of HotItem")

        if "thumbnail" in data:
            data["thumbnail"] = fix_url(data["thumbnail"])

        super(HotItem, self).__init__(data)

    def __repr__(self):
        return "HotItem (id: {})".format(self.id)

    def _format(self, log):
        log.info("hot item id        : {}".format(self.id))
        log.info("hot item name      : {}".format(self.name))
        log.info("hot item rank      : {}".format(self.rank))
        log.info("hot item published : {}".format(self.year))
        log.info("hot item thumbnail : {}".format(self.thumbnail))

    @property
    def rank(self):
        """
        :return: Ranking of this hot item
        """
        return self._data["rank"]

    @property
    def year(self):
        """
        Year this item was published

        :return: integer representing the year
        :return: ``None`` if object doesn't refer to a game
        """
        return self._data.get("yearpublished")

    @property
    def thumbnail(self):
        """
        :return: url of the thumbnail corresponding to this item
        """
        return self._data.get("thumbnail")


class HotItems(DictObject):
    """
    A container for :class:`boardgamegeek.hotitems.HotItem`
    """
    def __init__(self, data):
        kw = copy(data)
        if "items" not in kw:
            kw["items"] = []

        self._items = []
        for data in kw["items"]:
            self._items.append(HotItem(data))

        super(HotItems, self).__init__(kw)

    def add_hot_item(self, data):
        """
        Add a new hot item to the container

        :param data: dictionary containing the data

        """
        self._data["items"].append(data)
        self._items.append(HotItem(data))

    @property
    def items(self):
        """

        :return: the list of :class:`boardgamegeek.hotitems.HotItem`
        """
        return self._items

    def __len__(self):
        return len(self._items)

    def __iter__(self):
        for item in self._data["items"]:
            yield HotItem(item)

    def __getitem__(self, item):
        return self._items.__getitem__(item)

{'fraction_non_alphanumeric': 0.1470042194092827, 'fraction_numerical': 0.00033755274261603374, 'mean_word_length': 2.4736225087924972, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2067428', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1710, 'n_words': 487}