__author__ = 'iv'

import argparse as ap
import json
import sys

import checker.datachecker as dc

def get_command_line_arguments():
    parser = ap.ArgumentParser("")
    parser.add_argument('--target', '-t', required=True, type=str, help="'plots' or 'data'")
    parser.add_argument('--start', '-s', required=True, type=str, help="'start date given as YYYY-mm-dd'")
    parser.add_argument('--end', '-e', required=True, type=str, help="'end date given as YYYY-mm-dd'")
    return parser.parse_args()

def main():
    # Read the configuration file
    configuration_json = r'Configuration/configuration.json'
    with open(configuration_json, 'r') as fp:
        configuration = json.load(fp)
    cmdline = get_command_line_arguments()
    data_type=cmdline.target.strip()
    start = cmdline.start.strip()
    end = cmdline.end.strip()

    if 'plots' in data_type:
        # Find list of missing plots and export the result
        missing_plots = dc.get_period_missing_plots(configuration, start, end)
        dc.export_missing_plots_results(missing_plots, configuration, start, end)
    elif 'data' in data_type:
        # Find list of missing plots and export the result
        missing_data = dc.get_period_missing_data(configuration, start, end)
        dc.export_missing_data_results(missing_data, configuration, start, end)
    else:
        print 'Unknown target detected. Exiting'
        return 0

if __name__ == '__main__':
    sys.exit(main())
