Short Code Example

class Rainbow(object):
    """A rainbow object that can be applied to a string"""

    def __init__(self, color_count=None, start_color=None, end_color=None, output_format=None):

        conf = parse_config('config.ini')

        self.color_count = int(conf['color_count'])
        self.start_color = conf['start_color']
        self.current_color = conf['start_color']
        self.index = None
        self.end_color = conf['end_color']
        self.output_format = conf['format']
        self.rainbow = []
        self.cpc = 1

        if color_count:
            self.color_count = int(color_count)

        if start_color:
            self.start_color = start_color
            self.current_color = start_color

        if end_color:
            self.end_color = end_color

        if output_format:
            self.output_format = output_format

        with open(conf['formats_file']) as f:
            self.formats = json.loads(f.read())

        if self.output_format in self.formats:
            self.template = self.formats[self.output_format]
        else:
            raise RuntimeError('format not found! Are you sure it exists in ' + conf['formats_file'] + '?')

    def __iter__(self):
        return self

    def __next__(self):
        try:
            result = self.rainbow[self.index]
        except IndexError:
            raise StopIteration

        self.index += 1

        return result
date_range Date Published
folder Category
label Tags