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_none(self): assert mod.iso8601_to_dt(None, 'ext') is None
def test_invalid_long(self): with pytest.raises(ValueError): mod.iso8601_to_dt('2016-01-02T03-04-05-123456', 'ext')
def test_invalid_short(self): with pytest.raises(ValueError): mod.iso8601_to_dt('2016:01:02T03:04:05', 'ext')
def test_valid_long(self): assert mod.iso8601_to_dt('2016-01-02T03:04:05.123456', 'ext') == datetime.datetime(2016,1,2,3,4,5,123456)
def test_valid_short(self): assert mod.iso8601_to_dt('2016-01-02T03:04:05', 'ext') == datetime.datetime(2016, 1,2,3,4,5)
def test_invalid_misc(self): with pytest.raises(ValueError): mod.iso8601_to_dt('20160102 030405', 'basic')
def test_invalid_long(self): with pytest.raises(ValueError): mod.iso8601_to_dt('20160102 030405123456', 'basic')
def test_valid_long(self): assert mod.iso8601_to_dt('20160102T030405123456', 'basic') == datetime.datetime(2016, 1,2,3,4,5, 123456)
def test_valid_short(self): assert mod.iso8601_to_dt('20160102T030405', 'basic') == datetime.datetime(2016, 1, 2, 3, 4, 5)