From 5d750f57ee636d66f019c37451d4dd90460f64de Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Wed, 28 Jul 2021 22:36:14 -0500 Subject: [PATCH] =?UTF-8?q?Agregar=20soporte=20para=20intervalo=20de=20d?= =?UTF-8?q?=C3=ADas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/cfdi-descarga.py | 4 ++-- source/sat/util.py | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/cfdi-descarga.py b/source/cfdi-descarga.py index c80aefa..4f29d5e 100755 --- a/source/cfdi-descarga.py +++ b/source/cfdi-descarga.py @@ -53,8 +53,8 @@ def _process_command_line_arguments(): parser.add_argument('-d', '--dia', help=help, dest='day', default=0, type=int, choices=range(32)) help = "Intervalo de días a partir de la fecha actual y hacia a atras" - parser.add_argument('-id', '--intervalo-dias', help=help, - dest='interval_days', default=0, type=int, choices=range(30)) + parser.add_argument('-ud', '--ultimos-dias', help=help, + dest='last_days', default=0, type=int, choices=range(30)) help = 'Solicitar descarga' parser.add_argument('-sd', '--solicitar-descarga', help=help, diff --git a/source/sat/util.py b/source/sat/util.py index 0cf49ae..dcb425e 100644 --- a/source/sat/util.py +++ b/source/sat/util.py @@ -3,7 +3,7 @@ import getpass import uuid from calendar import monthrange -from datetime import datetime +from datetime import datetime, timedelta from pathlib import Path from time import sleep @@ -134,9 +134,6 @@ def _validate_requests_args(args): log.error(msg) return False, {} - # ~ cer = data['path_cer'].read_bytes() - # ~ key = data['path_enc'].read_bytes() - # ~ cert = SATCertificate(cer, key) cert = _get_cert(data) if not cert.is_valid_time: @@ -150,14 +147,22 @@ def _validate_requests_args(args): data['month'] = args.month data['day'] = args.day + now = today() + + if args.last_days: + date_start = now.replace(hour=0, minute=0, second=0, microsecond=0) \ + - timedelta(days=args.last_days) + date_end = now.replace(hour=23, minute=59, second=59, microsecond=0) + data['date_start'] = date_start + data['date_end'] = date_end + return True, data + if data['day']: if not validate_date(data['year'], data['month'], data['day']): msg = 'Fecha inválida' log.error(msg) return False, {} - now = today() - month1 = month2 = data['month'] if month1 == 0: month1 = 1