import os

import docopt

from . import __version__
from .provider import ResourceProvider
from .champion import get_champions
from .item import get_items


def main(args):
    path = args['--path']
    if not os.path.isdir(path):
        print('Invalid directory "%s"' % path)
    provider = ResourceProvider(
        lol_path=path,
        language=args['--lang']
    )
    champions = get_champions(provider)
    items = get_items(provider)
    # TODO: Save output

if __name__ == '__main__':
    main(docopt.docopt(__doc__, version='LoLDB v%s' % __version__))

import json
import os

import docopt

from . import __version__
from .provider import ResourceProvider
from .champion import get_champions
from .item import get_items
from .converter import (
    format_champion,
    format_item,
)
from .validate import validate_champions


class Encoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, set):
            return list(o)
        return super(Encoder, self).default(o)


def main(args):
    path = args['--path']
    if not os.path.isdir(path):
        print('Invalid directory "%s"' % path)
    output_path = args['--out']
    provider = ResourceProvider(
        lol_path=path,
        language=args['--lang']
    )
    champions = get_champions(provider)
    print('\n'.join(validate_champions(champions)))
    champions = map(format_champion, champions)

    items = get_items(provider)
    items = dict(zip(items.keys(), map(format_item, items.values())))

    output = {
        'champions': champions,
        'items': items,
    }
    output = json.dumps(output, cls=Encoder)
    if output_path is not None:
        with open(args['--out'], 'w') as f:
            f.write(output)
    else:
        print(output)

if __name__ == '__main__':
    main(docopt.docopt(__doc__, version='LoLDB v%s' % __version__))

Save data to file from CLI.
Save data to file from CLI.

+ import json
  import os
  
  import docopt
  
  from . import __version__
  from .provider import ResourceProvider
  from .champion import get_champions
  from .item import get_items
+ from .converter import (
+     format_champion,
+     format_item,
+ )
+ from .validate import validate_champions
+ 
+ 
+ class Encoder(json.JSONEncoder):
+     def default(self, o):
+         if isinstance(o, set):
+             return list(o)
+         return super(Encoder, self).default(o)
  
  
  def main(args):
      path = args['--path']
      if not os.path.isdir(path):
          print('Invalid directory "%s"' % path)
+     output_path = args['--out']
      provider = ResourceProvider(
          lol_path=path,
          language=args['--lang']
      )
      champions = get_champions(provider)
+     print('\n'.join(validate_champions(champions)))
+     champions = map(format_champion, champions)
+ 
      items = get_items(provider)
-     # TODO: Save output
+     items = dict(zip(items.keys(), map(format_item, items.values())))
+ 
+     output = {
+         'champions': champions,
+         'items': items,
+     }
+     output = json.dumps(output, cls=Encoder)
+     if output_path is not None:
+         with open(args['--out'], 'w') as f:
+             f.write(output)
+     else:
+         print(output)
  
  if __name__ == '__main__':
      main(docopt.docopt(__doc__, version='LoLDB v%s' % __version__))
  
Save data to file from CLI.
## Code Before:
import os

import docopt

from . import __version__
from .provider import ResourceProvider
from .champion import get_champions
from .item import get_items


def main(args):
    path = args['--path']
    if not os.path.isdir(path):
        print('Invalid directory "%s"' % path)
    provider = ResourceProvider(
        lol_path=path,
        language=args['--lang']
    )
    champions = get_champions(provider)
    items = get_items(provider)
    # TODO: Save output

if __name__ == '__main__':
    main(docopt.docopt(__doc__, version='LoLDB v%s' % __version__))

## Instruction:
Save data to file from CLI.
## Code After:
import json
import os

import docopt

from . import __version__
from .provider import ResourceProvider
from .champion import get_champions
from .item import get_items
from .converter import (
    format_champion,
    format_item,
)
from .validate import validate_champions


class Encoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, set):
            return list(o)
        return super(Encoder, self).default(o)


def main(args):
    path = args['--path']
    if not os.path.isdir(path):
        print('Invalid directory "%s"' % path)
    output_path = args['--out']
    provider = ResourceProvider(
        lol_path=path,
        language=args['--lang']
    )
    champions = get_champions(provider)
    print('\n'.join(validate_champions(champions)))
    champions = map(format_champion, champions)

    items = get_items(provider)
    items = dict(zip(items.keys(), map(format_item, items.values())))

    output = {
        'champions': champions,
        'items': items,
    }
    output = json.dumps(output, cls=Encoder)
    if output_path is not None:
        with open(args['--out'], 'w') as f:
            f.write(output)
    else:
        print(output)

if __name__ == '__main__':
    main(docopt.docopt(__doc__, version='LoLDB v%s' % __version__))
