From fa86be39133a5298d8a12a699969b36117bd83fc Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Thu, 8 Apr 2021 19:31:23 +0200 Subject: [PATCH] Enhance error catching in feed_periods --- app/commands/commands.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/commands/commands.py b/app/commands/commands.py index a86427f..d5bda86 100644 --- a/app/commands/commands.py +++ b/app/commands/commands.py @@ -88,14 +88,19 @@ def feed_from_lesia(): @bp.cli.command("feed_periods") -def feed_periods(): - """ Fill in the periods name in the database. """ - for y in range(2014, 2023): +@click.option('--begin-year', '-b', 'begin_year', default=2005, help="the start year to begin periods with") +@click.option('--end-year', '-e', 'end_year', default=2025, help="the last year to end periods with") +def feed_periods(begin_year, end_year): + """ Fill in the periods names in the database. """ + for y in range(begin_year, end_year): for s in ['S1', 'S2']: period_name = "{}_{}".format(y, s) p = Period(name=period_name) db.session.add(p) - db.session.commit() + try: + db.session.commit() + except IntegrityError: + current_app.logger.error("Periods already exist") @bp.cli.command("feed_random_charges") -- libgit2 0.21.2