Skip to content

Commit

Permalink
Making use of CLI arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
S1SYPHOS committed May 5, 2019
1 parent c5ee12d commit d89b01d
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 43 deletions.
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,35 @@ This library provides an easy way to generate [*color palettes*](https://www.ety
.. featuring [PANTONE®](https://www.pantone.com), [RAL®](https://www.ral-farben.de), [Dulux®](https://www.dulux.com.au) as well as [Copic®](https://www.copicmarker.com) and [Prismacolor®](https://www.prismacolor.com) (proprietary color spaces). For now, `we-love-colors` creates master palettes for use in [Scribus](https://www.scribus.net), an open source desktop publishing program, as well as [GIMP](https://www.gimp.org) and [Inkscape](https://inkscape.org).

## Getting started
.. was never easier. Make sure Python3 is intalled on your system, then simply do:
Depending on your setup you might prefer a ..

### Local installation via `virtualenv`
Running `setup.sh` will install all dependencies inside a virtual environment, ready for action.

### Global installation via `requirements.txt`
It's as easy as `pip install -r requirements.txt`, but you might want to make sure that Python v3 is installed on your system.

## Usage
Fetching color sets and processing them is really straightforward - for everything else, there's `--help`:

```bash
python3 fetch.py # or any other `fetch*` script
python3 process.py
$ python main.py
Usage: main.py [OPTIONS] COMMAND [ARGS]...

Options:
-v, --version Show the version and exit.
-h, --help Show this message and exit.

Commands:
fetch ARGS: pantone | ral | dulux | copic | prismacolor
process ARGS: pantone | ral | dulux | copic | prismacolor


# Example 1 - Gotta fetch 'em `--all`:
$ python main.py fetch --all && python main.py process --all

# Example 2 - Fetching two sets & processing them:
$ python main.py fetch copic dulux && python main.py process copic dulux # or simply `--all`
```

## Color samples
Expand Down Expand Up @@ -48,7 +72,7 @@ We assume neither ownership nor intellectual property of any kind - color codes
- [x] Filtering neons, pastels & metallics
- [x] Adding copyright notice for RAL®/Dulux® (XML + GPL) + fallback option
- [x] Adding examples for all color palettes
- [ ] Making use of CLI arguments
- [x] Making use of CLI arguments
- [x] Automatizing example generation
- [x] Combining all `fetch` scripts
- [x] Cleaning up examples (merge CSS, remove RGB2hex & PHP error settings)
2 changes: 1 addition & 1 deletion lib/copic.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self):
# Valid `set_name` parameter:
# - 'copic', currently 289 colors
##
def fetch(self, set_name):
def fetch(self, set_name='copic'):
# One baseURL to rule them all
base_url = 'https://www.copicmarker.com/collections/collect'

Expand Down
2 changes: 1 addition & 1 deletion lib/dulux.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self):
# Valid `set_name` parameter:
# - 'dulux', currently 1768 colors
##
def fetch(self, set_name):
def fetch(self, set_name='dulux'):
# One baseURL to rule them all
base_url = 'https://colour.dulux.ca/all-colors'

Expand Down
9 changes: 9 additions & 0 deletions lib/pantone.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def fetch(self, set_name, firstPage, lastPage):
print('Loading ' + color['code'] + ' in set "' + set_name + '" .. done')


##
# Fetches all PANTONE® colors at once
##
def fetch_all(self):
self.fetch('graphic-design', 1, 32)
self.fetch('fashion-design', 1, 14)
self.fetch('product-design', 1, 10)


##
# Creates JSON files for Dulux® color sets
##
Expand Down
2 changes: 1 addition & 1 deletion lib/prismacolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self):
# Valid `set_name` parameter:
# - 'premier', currently 150 colors
##
def fetch(self, set_name):
def fetch(self, set_name='premier'):
# One baseURL to rule them all
base_url = 'https://kredki.eu/pl/p/Prismacolor-Colored-Pencils-Kredki-Art-150-Kol/75'

Expand Down
12 changes: 11 additions & 1 deletion lib/ral.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from palette import Palette


class Ral(Palette):
class RAL(Palette):
# Dictionary holding fetched colors
sets = {
'classic': [],
Expand Down Expand Up @@ -114,3 +114,13 @@ def fetch(self, set_name):
self.sets[identifier].append(color)

print('Loading ' + color['code'] + ' in set "' + set_name + '" .. done')


##
# Fetches all RAL® colors at once
##
def fetch_all(self):
self.fetch('classic')
self.fetch('design')
self.fetch('effect')
self.fetch('plastics')
108 changes: 73 additions & 35 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,82 @@
# IMPORTS
# For more information, see https://www.python.org/dev/peps/pep-0008/#imports
##
import click

from lib.pantone import Pantone
from lib.ral import Ral
from lib.ral import RAL
from lib.dulux import Dulux
from lib.copic import Copic
from lib.prismacolor import Prismacolor

pantone = Pantone()
pantone.fetch('graphic-design', 1, 32)
pantone.fetch('fashion-design', 1, 14)
pantone.fetch('product-design', 1, 10)
pantone.save()
pantone.create_json()
pantone.make_palettes()

ral = Ral()
ral.fetch('classic')
ral.fetch('design')
ral.fetch('effect')
ral.fetch('plastics')
ral.save()
ral.create_json()
ral.make_palettes()

dulux = Dulux()
dulux.fetch('dulux')
dulux.save()
dulux.create_json()
dulux.make_palettes()

copic = Copic()
copic.fetch('copic')
copic.save()
copic.create_json()
copic.make_palettes()

prismacolor = Prismacolor()
prismacolor.fetch('premier')
prismacolor.save()
prismacolor.create_json()
prismacolor.make_palettes()

CONTEXT_SETTINGS = dict(
help_option_names=['-h', '--help'],
)



class_map = {
'dulux': Dulux,
'copic': Copic,
'prismacolor': Prismacolor,
}

@click.group(context_settings=CONTEXT_SETTINGS)
@click.version_option(None, '-v', '--version')
def cli():
pass

@cli.command()
@click.argument('sets', nargs=-1)
@click.option('--all', 'fetch_all', flag_value=True, help='Fetch all available color sets & save as JSON.')
def fetch(sets, fetch_all):
"""
ARGS:
pantone | ral | dulux | copic | prismacolor
"""
valid_sets = list(class_map.keys())

if fetch_all == True:
sets = valid_sets

for set in sets:
if set in valid_sets:
object = class_map[set]()

try:
object.fetch_all()
except AttributeError:
object.fetch()

object.save()
object.create_json()
else:
print('"' + set + '" isn\'t available. Please provide a valid color space,\nsuch as "pantone", "ral", "dulux", "copic" & "prismacolor".')
continue


@cli.command()
@click.argument('sets', nargs=-1)
@click.option('--all', 'process_all', flag_value=True, help='Process all available color sets & generate color palettes.')
def process(sets, process_all):
"""
ARGS:
pantone | ral | dulux | copic | prismacolor
"""
valid_sets = list(class_map.keys())

if process_all == True:
sets = valid_sets

for set in sets:
if set in valid_sets:
object = class_map[set]()
object.make_palettes()
else:
print('"' + set + '" isn\'t available. Please provide a valid color space,\nsuch as "pantone", "ral", "dulux", "copic" & "prismacolor".')
continue


if __name__ == '__main__':
cli()

1 comment on commit d89b01d

@S1SYPHOS
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit flixes #4

Please sign in to comment.