コード例 #1
0
def config_colors(col_source, col_params):

    # get palette from matplotlib
    if col_source == 'matplotlib':
        try:
            num_col = col_params['col_num']
            step = 256 / num_col
            cmap = cm.get_cmap(col_params['cmap'], 256)
            colors = 255 * cmap(np.arange(0, 256, step))[:, :-1]
            colors = colors.astype(int)
        except ValueError:
            print 'Colormap not recognized -- using default color scheme'
            colors = [[0, 255, 255], [128, 128, 255], [255, 0, 255],
                      [255, 128, 128]]
            colors = np.array(colors)

    # get palette from www.colourlovers.com
    elif col_source == 'colourlovers':
        cl = ColourLovers()
        palette = cl.palettes(**col_params)[0]
        colors = palette.colours
        for i in range(len(colors)):
            colors[i] = hex_to_rgb(colors[i])
        colors = np.array(colors)
    else:
        print 'Color source not recognized -- using default color scheme'
        colors = [[0, 255, 255], [128, 128, 255], [255, 0, 255],
                  [255, 128, 128]]
        colors = np.array(colors)

    return colors
コード例 #2
0
def config_colors(col_source, col_params):

    # get palette from matplotlib
    if col_source == 'matplotlib':
        try:
            num_col = col_params['col_num']
            step = 256 / num_col
            cmap = cm.get_cmap(col_params['cmap'], 256)
            colors = 255 * cmap(np.arange(0, 256, step))[:,:-1]
            colors = colors.astype(int)
        except ValueError:
            print 'Colormap not recognized -- using default color scheme'
            colors = [[0, 255, 255], [128, 128, 255], [255, 0, 255], [255, 128, 128]]
            colors = np.array(colors)

    # get palette from www.colourlovers.com
    elif col_source == 'colourlovers':
            cl = ColourLovers()
            palette = cl.palettes(**col_params)[0]
            colors = palette.colours
            for i in range(len(colors)):
                colors[i] = hex_to_rgb(colors[i])
            colors = np.array(colors)
    else:
        print 'Color source not recognized -- using default color scheme'
        colors = [[0, 255, 255], [128, 128, 255], [255, 0, 255], [255, 128, 128]]
        colors = np.array(colors)

    return colors
コード例 #3
0
    def test_colors(self):
        cl_api = ColourLovers()

        for argument in ['new', 'top', 'random']:
            results = cl_api.colors(argument)

            for result in results:
                self.assertEquals(type(result), Colour)

        self.assertRaises(ColourLoversError, cl_api.colors, 'invalid_argument')
コード例 #4
0
    def test_color(self):
        cl_api = ColourLovers()

        for hexstr in ['6B4106', '#6b4106']:
            res = cl_api.color(hexstr)
            self.assertEquals(len(res), 1)
            self.assertEquals(type(res[0]), Colour)
            self.assertEquals(res[0].hex, '#6b4106')

        self.assertRaises(ColourLoversError, cl_api.color, '6B410')
コード例 #5
0
    def test_method_calls(self):
        cl_api = ColourLovers()
        res = cl_api.color('6B4106')
        res = cl_api.color('#6B4106')

        self.assertRaises(
            ColourLoversError,
            cl_api.color,
            '6B410'
        )
コード例 #6
0
    def test_for_colour_returns_valid_object(self):
        httpretty.enable()
        httpretty.register_uri(httpretty.GET,
                               "{0}/color".format(self.API_URL),
                               body=self.data['colour.xml'])

        cl = ColourLovers()
        colours = cl.color('#37cbff')

        self.assertTrue(isinstance(colours[0], Colour))
        self.assertEquals(colours[0].hex, '#37cbff')

        httpretty.disable()
コード例 #7
0
    def test_color(self):
        cl_api = ColourLovers()

        for hexstr in ['6B4106', '#6b4106']:
            res = cl_api.color(hexstr)
            self.assertEquals(len(res), 1)
            self.assertEquals(type(res[0]), Colour)
            self.assertEquals(res[0].hex, '#6b4106')

        self.assertRaises(
            ColourLoversError,
            cl_api.color,
            '6B410'
        )
コード例 #8
0
    def test_colors(self):
        cl_api = ColourLovers()

        for argument in ['new', 'top', 'random']:
            results = cl_api.colors(argument)

            for result in results:
                self.assertEquals(type(result), Colour)

        self.assertRaises(
            ColourLoversError,
            cl_api.colors,
            'invalid_argument'
        )
コード例 #9
0
    def test_for_colour_returns_valid_object(self):
        httpretty.enable()
        httpretty.register_uri(
            httpretty.GET,
            "{0}/color".format(self.API_URL),
            body=self.data['colour.xml']
        )

        cl = ColourLovers()
        colours = cl.color('#37cbff')

        self.assertTrue(isinstance(colours[0], Colour))
        self.assertEquals(colours[0].hex, '#37cbff')

        httpretty.disable()
コード例 #10
0
    def test_convert_keywords(self):
        keywords = {
            "order_col": 'score',
            "sortBy": 'DESC',
            "num_results": 20,
            "result_offset": 5,
            "format": 'json',
            "jsonCallback": 'somecallbackfunction',
        }
        converted_keywords = ColourLovers().convert_keywords(keywords)

        self.assertEquals(len(converted_keywords), 4)
        self.assertItemsEqual(
            converted_keywords.keys(),
            ['orderCol', 'sortBy', 'numResults', 'resultOffset'])
コード例 #11
0
def home():
    # get a random palette
    cl = ColourLovers()
    palette = cl.palettes('random').pop()
    palette_id, palette_title, colours = palette.id, palette.title, palette.colours

    return render_template('mockup.html', **{
        'colour1': get_colour(colours, 0),
        'colour2': get_colour(colours, 1),
        'colour3': get_colour(colours, 2),
        'colour4': get_colour(colours, 3),
        'colour5': get_colour(colours, 4),
        'palette_id': palette_id,
        'palette_title': palette_title,
        'mtime': str(os.path.getmtime(app.root_path + '/static/style.css'))
    })
コード例 #12
0
    def test_convert_keywords(self):
        keywords = {
            "order_col": 'score',
            "sortBy": 'DESC',
            "num_results": 20,
            "result_offset": 5,
            "format": 'json',
            "jsonCallback": 'somecallbackfunction',
        }
        converted_keywords = ColourLovers().convert_keywords(keywords)

        self.assertEquals(len(converted_keywords), 4)
        self.assertItemsEqual(
            converted_keywords.keys(),
            ['orderCol', 'sortBy', 'numResults', 'resultOffset']
        )
コード例 #13
0
 def _on_query(self):
     cl = ColourLovers()
     query_type = self._get_query_type()
     username = self.username.text()
     keywords = self.keywords.text()
     hue_idx = self.hue_option.currentIndex()
     hue = self.hue_option.itemData(hue_idx)
     opts = {}
     if username:
         opts['lover'] = username
     if keywords:
         opts['keywords'] = keywords
     if hue:
         opts['hueOption'] = str(hue.toString())
     print opts
     palettes = cl.palettes(query_type, **opts)
     self.table.set_palettes(palettes)
コード例 #14
0
def get_data(data_path, n_colors, chunk_size, sleep_time):
    """
    check http://www.colourlovers.com/api
    https://github.com/elbaschid/python-colourlovers
    """
    cl = ColourLovers()
    data = {}
    print(str(datetime.now()), "Begin download")
    for i in range(1, n_colors, chunk_size):
        if i % 100 == 0:
            print(str(datetime.now()), i)
        time.sleep(sleep_time)
        col = cl.colors(num_results=chunk_size, result_offset=i)
        for c in col:
            data[c.id] = {
                "title": c.title,
                "r": c.rgb.red,
                "g": c.rgb.green,
                "b": c.rgb.blue
            }

    print("Saving to disk")
    with open(join(data_path, "colors_raw.json"), "w") as f:
        json.dump(data, f)
コード例 #15
0
    def test_method_calls(self):
        cl_api = ColourLovers()
        res = cl_api.color('6B4106')
        res = cl_api.color('#6B4106')

        self.assertRaises(ColourLoversError, cl_api.color, '6B410')
コード例 #16
0
ファイル: script.py プロジェクト: jkenlooper/colourless
def main():
    args = docopt(__doc__)

    config = ConfigParser.SafeConfigParser()
    config.read(args['--config'])
    palette_urls = config.get('palettes', 'url')
    palette_ids = [int(x) for x in re.findall('palette/([0-9]+)/', palette_urls)]

    renderer = Renderer()

    if config.has_option('palettes', 'template'):
        template_file = config.get('palettes', 'template')
        f = open(template_file, 'r')
        template = f.read()
        f.close()
    else:
        template = """
{{#palettes}}
/** Colourlovers Palette
    {{title}}
    {{url}}
    by: {{user_name}}
    {{description}}
**/
{{#colors}}
/* {{title}} */
@color-{{normalized_title}}: {{hex}};
{{/colors}}

{{/palettes}}
        """

    d = { 'palettes':[] }

    cl = ColourLovers()
    for palette_id in palette_ids:
        for palette in cl.palette(palette_id):
            colors = []
            for hexcolor in palette.colours:
                c = cl.color(hexcolor)[0]
                a_colour = {
                        'badge_url': c.badge_url,
                        'date_created': c.date_created,
                        'description': c.description,
                        'hex': c.hex,
                        'hsv': c.hsv,
                        'id': c.id,
                        'image_url': c.image_url,
                        'rgb': c.rgb,
                        'title': c.title,
                        'normalized_title': re.sub('[^a-z_-]', '', c.title.lower()),
                        'url': c.url,
                        'user_name': c.user_name,
                        }
                colors.append(a_colour)
            d['palettes'].append({
                'badge_url': palette.badge_url,
                'date_created': palette.date_created,
                'description': palette.description,
                'id': palette.id,
                'image_url': palette.image_url,
                'title': palette.title,
                'normalized_title': re.sub('[^a-z_-]', '', palette.title.lower()),
                'url': palette.url,
                'user_name': palette.user_name,
                'colors':colors,
                })


    ctx = ContextStack(d)
    css_file = config.get('palettes', 'css')
    c = open(css_file, 'w')
    c.write( renderer.render(template, ctx) )
    c.close()
コード例 #17
0
ファイル: testing.py プロジェクト: RaviTmg/colours
from colourlovers import ColourLovers

cl = ColourLovers()
print(cl.palettes('top'))
コード例 #18
0
 def test_valid_methods(self):
     self.assertEquals(ColourLovers.valid_methods(), [
         'color', 'palette', 'pattern', 'lover', 'colors', 'palettes',
         'patterns', 'lovers', 'stats'
     ])
コード例 #19
0
def main():
    args = docopt(__doc__)

    config = ConfigParser.SafeConfigParser()
    config.read(args['--config'])
    palette_urls = config.get('palettes', 'url')
    palette_ids = [
        int(x) for x in re.findall('palette/([0-9]+)/', palette_urls)
    ]

    renderer = Renderer()

    if config.has_option('palettes', 'template'):
        template_file = config.get('palettes', 'template')
        f = open(template_file, 'r')
        template = f.read()
        f.close()
    else:
        template = """
{{#palettes}}
/** Colourlovers Palette
    {{title}}
    {{url}}
    by: {{user_name}}
    {{description}}
**/
{{#colors}}
/* {{title}} */
@color-{{normalized_title}}: {{hex}};
{{/colors}}

{{/palettes}}
        """

    d = {'palettes': []}

    cl = ColourLovers()
    for palette_id in palette_ids:
        for palette in cl.palette(palette_id):
            colors = []
            for hexcolor in palette.colours:
                c = cl.color(hexcolor)[0]
                a_colour = {
                    'badge_url': c.badge_url,
                    'date_created': c.date_created,
                    'description': c.description,
                    'hex': c.hex,
                    'hsv': c.hsv,
                    'id': c.id,
                    'image_url': c.image_url,
                    'rgb': c.rgb,
                    'title': c.title,
                    'normalized_title': re.sub('[^a-z_-]', '',
                                               c.title.lower()),
                    'url': c.url,
                    'user_name': c.user_name,
                }
                colors.append(a_colour)
            d['palettes'].append({
                'badge_url':
                palette.badge_url,
                'date_created':
                palette.date_created,
                'description':
                palette.description,
                'id':
                palette.id,
                'image_url':
                palette.image_url,
                'title':
                palette.title,
                'normalized_title':
                re.sub('[^a-z_-]', '', palette.title.lower()),
                'url':
                palette.url,
                'user_name':
                palette.user_name,
                'colors':
                colors,
            })

    ctx = ContextStack(d)
    css_file = config.get('palettes', 'css')
    c = open(css_file, 'w')
    c.write(renderer.render(template, ctx))
    c.close()
コード例 #20
0
 def test_valid_methods(self):
     self.assertEquals(
         ColourLovers.valid_methods(),
         ['color', 'palette', 'pattern', 'lover',
          'colors', 'palettes', 'patterns', 'lovers', 'stats']
     )