#!/usr/bin/env python3
"""
name   : reporter.py
author : nbehrnd@yahoo.com
license:
date   : <2023-06-06 Tue>
edit   :
purpose: some analysis on DW's exported .txt file
"""

import argparse
import re

def get_args():
    """Get command-line arguments"""

    parser = argparse.ArgumentParser(
        description='sample script to report some meta data',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('file',
                        help='the .txt file exported from DataWarrior',
                        metavar='FILE',
                        type=argparse.FileType('rt'),
                        default=None)

    return parser.parse_args()


def count_columns(raw_data):
    """determine the number of columns"""
    with open(raw_data, mode="rt", encoding="utf-8") as source:
        first_line = source.readline()
        columns = first_line.split("\t")
        print(f"number of columns: {len(columns)}")


def count_lines(raw_data):
    """determine the number of lines"""
    counter = 0
    with open(raw_data, mode="rt", encoding="utf-8") as source:
        for line in source:
            counter += 1
    print(f"number of lines: {counter}")
    print(f"number of data:  {counter - 1}")


def main():
    """Join the functionalities"""

    args = get_args()
    print(f"File of interest: {args.file.name}")

    count_columns(args.file.name)
    count_lines(args.file.name)


# --------------------------------------------------
if __name__ == '__main__':
    main()
