def main():
    next_start_dt       = None
    next_stop_dt        = None
    next_period_has_data = False

    args = get_args()
    validate_args(args)

    if args.mode == 'incremental':
        if args.data_start_ts_prior == '':
            first_dt = get_first_dt_by_ymd(args.inst, args.db, args.table, args.ssl)
            if first_dt:
                next_period_has_data = True
                next_start_dt       = tools.dt_override(first_dt, hour=0, minute=0, second=0, ms=0)
                next_stop_dt        = tools.dt_override(first_dt, hour=23, minute=59, second=59, ms=999999)
        else:
            try:
                next_start_dt, next_stop_dt = tools.get_next_dt(tools.iso8601_to_dt(args.data_start_ts_prior),
                                                                tools.iso8601_to_dt(args.data_stop_ts_prior))
            except ValueError:
                print('invalid data_start_ts_prior or data_stop_ts_prior: %s and %s' % (args.data_start_ts_prior, args.data_stop_ts_prior))
            next_period_has_data = does_period_have_data(args.inst, args.db, args.ssl, args.table, next_start_dt, next_stop_dt)
    else:
        next_period_has_data = does_period_have_data(args.inst, args.db, args.ssl, args.table, start_dt=None, stop_dt=None)

    results = {}
    if next_period_has_data:
        results['table_status']       = 'active'
        results['mode']               = args.mode
        if args.mode == 'incremental':
            results['data_start_ts']  = tools.dt_to_iso8601(next_start_dt, precision='second')
            results['data_stop_ts']   = tools.dt_to_iso8601(next_stop_dt, precision='second')
        else:
            results['data_start_ts']  = ''
            results['data_stop_ts']   = ''
    else:
        results['table_status']       = 'inactive'
        results['mode']               = args.mode
        results['data_start_ts']      = args.data_start_ts_prior
        results['data_stop_ts']       = args.data_stop_ts_prior

    results['rc'] = INTERNAL_STATUS_CD
    results['log'] = 'start_ts_prior: %s, stop_ts_prior: %s, next_period_has_data: %s'\
            % (args.data_start_ts_prior, args.data_stop_ts_prior, next_period_has_data)
    for (key, val) in os.environ.items():
        if 'hapinsp' in key:
            results['log'] += ', %s:%s' % (key, val)
    print(hapinsp_formatter.transform_args(results))
 def test_input_is_none(self):
     last_dt = None
     assert mod.get_next_dt(None, None)  == (None, None)
 def test_basics(self):
     last_start_dt = datetime.datetime(2015, 01, 02, 0, 0, 0)
     last_stop_dt = datetime.datetime(2015, 01, 02, 23, 59, 59)
     assert mod.get_next_dt(last_start_dt, last_stop_dt)  \
             == (datetime.datetime(2015, 01, 03, 0, 0, 0), datetime.datetime(2015, 1, 3, 23, 59, 59))