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