#!/usr/bin/env python
# -*- mode: python -*-
# PYTHON_ARGCOMPLETE_OK

import sys
import json
from xlsx2pandas.cli import get_args
from xlsx2pandas import get_df


def main():
    args = get_args()
    try:
        python_output = get_df(args.path, 
                               sheets=args.sheets,
                               prettify_output=False)
        # Convert the dataframes to csv strings
        converted_dict = {}
        for sheet_name, dfs in python_output.items():
            converted_dict[sheet_name] = [df.to_csv(index=False) for df in dfs]

        # Convert to JSON
        output = json.dumps(converted_dict, indent=4)
    except Exception as e:
        sys.stderr.write(e + '\n')
        sys.exit(1)
    else:
        print(output)


main()
