From 9f9c283dd96e70a12b1f9aa8c9215003d980033f Mon Sep 17 00:00:00 2001 From: Alias <93505057+aliassheikh@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:34:07 +0200 Subject: [PATCH] DD-1637 Add age option to deposit-createreport script (#66) * DD-1637 Add age option to deposit-createreport script * Update src/datastation/deposit_create_report.py * DD-1637 Add age option to deposit-createreport script - type age is int * DD-1637 Add age option to deposit-createreport script - type age is int - II --------- Co-authored-by: Ali Sheikhi Co-authored-by: Jo Pol --- src/datastation/deposit_create_report.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/datastation/deposit_create_report.py b/src/datastation/deposit_create_report.py index 1a25fe3..9fce711 100755 --- a/src/datastation/deposit_create_report.py +++ b/src/datastation/deposit_create_report.py @@ -1,4 +1,6 @@ import argparse +from datetime import date, timedelta + from datastation.managedeposit.manage_deposit import ManageDeposit from datastation.common.config import init from datastation.common.send_mail import SendMail @@ -46,7 +48,11 @@ def main(): parser.add_argument('-o', '--output-file', dest='output_file', default='-', help='the file to write the output and send recipient to a to or - for stdout') parser.add_argument('-e', '--enddate', dest='enddate', help='Filter until the record creation of this date') - parser.add_argument('-s', '--startdate', dest='startdate', help='Filter from the record creation of this date') + + group = parser.add_mutually_exclusive_group(required=False) + group.add_argument('-s', '--startdate', dest='startdate', help='Filter from the record creation of this date') + group.add_argument('-a', '--age', dest='age', type=int, help='Filter from record creation not older than a number of days before today ') + parser.add_argument('-t', '--state', help='The state of the deposit (repeatable)', action='append') parser.add_argument('-u', '--user', dest='user', help='The depositor name (repeatable)', action='append') parser.add_argument('-f', '--format', dest='file_format', default='text/csv', help='Output data format') @@ -56,6 +62,9 @@ def main(): parser.add_argument('--bcc-email-to', dest='bcc_email_to', help='will be sent only if email-to is defined') args = parser.parse_args() + if args.age is not None: # Note: args is a Namespace object + vars(args)['startdate'] = (date.today() + timedelta(days=-args.age)).strftime('%Y/%m/%d') + server_url = config['manage_deposit']['service_baseurl'] + '/report' ReportHandler(server_url, args).handle_request()