#!/usr/bin/env python

import os
import sys
from clint import arguments, textui

sys.path.insert(0, os.path.abspath('.'))
import jsuite

def extract(to_extract, doc):
  if to_extract == 'article-title':
    title = jsuite.extract.extract_title(doc)
    textui.puts(title)

def content(to_content, doc):
  if to_content == 'body':
    textui.puts(jsuite.content.body_text(doc))

USAGE = """
Supported commands

> jsuite --extract article-title <file>
> jsuite --content body <file>
"""

if __name__ == "__main__":
  args = arguments.Args()

  handled = False

  if len(args.files) is 1:
    if '--extract' in args.grouped:
      handled = True
      to_extract = args.grouped.get('--extract')[0]
      with open(args.files[0]) as f:
        extract(to_extract, jsuite.from_file(f))

    if '--content' in args.grouped:
      handled = True
      to_content = args.grouped.get('--content')[0]
      with open(args.files[0]) as f:
        content(to_content, jsuite.from_file(f))
  else:
    textui.puts('No files provided')

  if not handled:
    with textui.indent(4):
      textui.puts(USAGE)
    sys.exit(1)
