<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
    executable to convert yaml input into groceries.app
    compatible shopping lists
"""

import yaml
import sys

from os.path import expanduser
from optparse import OptionParser
from lib.__version__ import __version__
from lib.groceries_exporter import GroceriesExporter

GROCERIES_PATH = expanduser("~")+"/.groceries_exporter/groceries.json"
GROCERIES_TEMPLATE = expanduser("~")+"/.groceries_exporter/groceries.mustache"


def init_parser():
    """method to init options parser"""
        # initialize parser
    usage = "usage: %prog [-j groceries_dump] [-t template] groceries.yaml"
    parser = OptionParser(usage, version="%prog "+__version__)
    parser.add_option("-j", "--groceries_dump", action="store",
                      dest="groceries_json", help="groceries json dump")
    parser.add_option("-t", "--template", action="store", dest="template",
                      help="mustache template to fill")

    return parser.parse_args()

def main():
    """ main function
    """
    (options, args) = init_parser()

    if not options.groceries_json:
        groceries_file = GROCERIES_PATH
    else:
        groceries_file = options.groceries_json
    print groceries_file

    gc = GroceriesExporter(groceries_file)
    if gc == None:
        sys.exit(-1)
    groceries = yaml.safe_load(open(args[0]).read())
    print gc.export_list(groceries)

if __name__ == '__main__':<commit_msg>add pystache support<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
    executable to convert yaml input into groceries.app
    compatible shopping lists
"""

import yaml
import sys
import pystache

from os.path import expanduser
from optparse import OptionParser
from lib.__version__ import __version__
from lib.groceries_exporter import GroceriesExporter

GROCERIES_PATH = expanduser("~")+"/.groceries_exporter/groceries.json"
GROCERIES_TEMPLATE = expanduser("~")+"/.groceries_exporter/groceries.mustache"


def init_parser():
    """method to init options parser"""
        # initialize parser
    usage = "usage: %prog [-j groceries_dump] [-t template] groceries.yaml"
    parser = OptionParser(usage, version="%prog "+__version__)
    parser.add_option("-j", "--groceries_dump", action="store",
                      dest="groceries_json", help="groceries json dump")
    parser.add_option("-t", "--template", action="store", dest="template",
                      help="mustache template to fill")

    return parser.parse_args()

def main():
    """ main function
    """
    (options, args) = init_parser()

    if not options.groceries_json:
        groceries_file = GROCERIES_PATH
    else:
        groceries_file = options.groceries_json

    if not options.template:
        template = open(GROCERIES_TEMPLATE).read()
    else:
        template = open(options.template).read()

    gc = GroceriesExporter(groceries_file)
    if gc == None:
        sys.exit(-1)
    groceries = yaml.safe_load(open(args[0]).read())
    data_json = gc.export_list(groceries)
    items = gc.data['items']
    ctx = {}
    ctx['groceries'] = data_json
    ctx['listname'] = gc.data['name']
    ctx['itemcount'] = len(gc.data['items'])
    ctx["items"] = gc.list_data
    output = pystache.render(template, ctx)
    print output


if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.12597950572634117, 'fraction_numerical': 0.0018083182640144665, 'mean_word_length': 3.5403556771545825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1266565', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1042, 'n_words': 237}