giphypop.py
def _make_images(self, images):
        """
        Takes an image dict from the giphy api and converts it to attributes.
        Any fields expected to be int (width, height, size, frames) will be attempted
        to be converted. Also, the keys of `data` serve as the attribute names, but
        with special action taken. Keys are split by the last underscore; anything prior
        becomes the attribute name, anything after becomes a sub-attribute. For example:
        fixed_width_downsampled will end up at `self.fixed_width.downsampled`
        """
        # Order matters :)
        process = ('original',
                   'fixed_width',
                   'fixed_height',
                   'fixed_width_downsampled',
                   'fixed_width_still',
                   'fixed_height_downsampled',
                   'fixed_height_still',
                   'downsized')

        for key in process:
            data = images.get(key)

            # Ignore empties
            if not data:
                continue

            parts = key.split('_')

            # attr/subattr style
            if len(parts) > 2:
                attr, subattr = '_'.join(parts[:-1]), parts[-1]
            else:
                attr, subattr = '_'.join(parts), None

            # Normalize data
            img = AttrDict(self._normalized(data))

            if subattr is None:
                setattr(self, attr, img)
            else:
                setattr(getattr(self, attr), subattr, img)
def _make_images(self, images):
        """
        Takes an image dict from the giphy api and converts it to attributes.
        Any fields expected to be int (width, height, size, frames) will be attempted
        to be converted. Also, the keys of `data` serve as the attribute names, but
        with special action taken. Keys are split by the last underscore; anything prior
        becomes the attribute name, anything after becomes a sub-attribute. For example:
        fixed_width_downsampled will end up at `self.fixed_width.downsampled`
        """
        # Order matters :)
        process = ('original',
                   'fixed_width',
                   'fixed_height',
                   'fixed_width_downsampled',
                   'fixed_width_still',
                   'fixed_height_downsampled',
                   'fixed_height_still',
                   'downsized')

        for key in process:
            data = images.get(key)

            # Ignore empties
            if not data:
                continue

            parts = key.split('_')

            # attr/subattr style
            if len(parts) > 2:
                attr, subattr = '_'.join(parts[:-1]), parts[-1]
            else:
                attr, subattr = '_'.join(parts), None

            # Normalize data
            img = AttrDict(self._normalized(data))

            if subattr is None:
                setattr(self, attr, img)
            else:
                setattr(getattr(self, attr), subattr, img)
Takes an image dict from the giphy api and converts it to attributes.
        Any fields expected to be int (width, height, size, frames) will be attempted
        to be converted. Also, the keys of `data` serve as the attribute names, but
        with special action taken. Keys are split by the last underscore; anything prior
        becomes the attribute name, anything after becomes a sub-attribute. For example:
        fixed_width_downsampled will end up at `self.fixed_width.downsampled`