From 3db68cd07956d53e92b55943caeb6a6838af09e1 Mon Sep 17 00:00:00 2001 From: Dan Nguyen <186835528+dnguyen1-pass@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:20:32 +0100 Subject: [PATCH] (BSR)[API] fix: titelive sync commands call --- api/src/pcapi/core/providers/titelive_api.py | 4 +-- .../scheduled_tasks/titelive_commands.py | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/api/src/pcapi/core/providers/titelive_api.py b/api/src/pcapi/core/providers/titelive_api.py index 90f99ef6acf..97d40de616c 100644 --- a/api/src/pcapi/core/providers/titelive_api.py +++ b/api/src/pcapi/core/providers/titelive_api.py @@ -116,13 +116,11 @@ def log_sync_status( def get_updated_titelive_pages( self, from_date: datetime.date, to_date: datetime.date, from_page: int ) -> typing.Iterator[list[TiteliveWorkType]]: - updated_date = from_date page_index = from_page days = (to_date - from_date).days for day_offset in range(days + 1): - updated_date += datetime.timedelta(days=day_offset) - + updated_date = from_date + datetime.timedelta(days=day_offset) has_next_page = True while has_next_page: json_response = titelive.search_products(self.titelive_base, updated_date, page_index) diff --git a/api/src/pcapi/scheduled_tasks/titelive_commands.py b/api/src/pcapi/scheduled_tasks/titelive_commands.py index abc8702bfaf..2164ac23d30 100644 --- a/api/src/pcapi/scheduled_tasks/titelive_commands.py +++ b/api/src/pcapi/scheduled_tasks/titelive_commands.py @@ -23,6 +23,12 @@ type=click.DateTime(), default=None, ) +@click.option( + "--to-date", + help="sync music products that were modified before to_date (YYYY-MM-DD)", + type=click.DateTime(), + default=None, +) @click.option( "--from-page", help="page to sync from, defaults to 1", @@ -31,8 +37,12 @@ ) @log_cron_with_transaction @cron_require_feature(FeatureToggle.SYNCHRONIZE_TITELIVE_API_MUSIC_PRODUCTS) -def synchronize_titelive_music_products(from_date: datetime.datetime | None, from_page: int) -> None: - TiteliveMusicSearch().synchronize_products(from_date.date() if from_date else None, from_page) +def synchronize_titelive_music_products( + from_date: datetime.datetime | None, to_date: datetime.datetime | None, from_page: int +) -> None: + TiteliveMusicSearch().synchronize_products( + from_date.date() if from_date else None, to_date.date() if to_date else None, from_page + ) @blueprint.cli.command("synchronize_titelive_book_products") @@ -42,6 +52,12 @@ def synchronize_titelive_music_products(from_date: datetime.datetime | None, fro type=click.DateTime(), default=None, ) +@click.option( + "--to-date", + help="sync music products that were modified before to_date (YYYY-MM-DD)", + type=click.DateTime(), + default=None, +) @click.option( "--from-page", help="page to sync from, defaults to 1", @@ -50,5 +66,9 @@ def synchronize_titelive_music_products(from_date: datetime.datetime | None, fro ) @log_cron_with_transaction @cron_require_feature(FeatureToggle.SYNCHRONIZE_TITELIVE_PRODUCTS) -def synchronize_titelive_book_products(from_date: datetime.datetime | None, from_page: int) -> None: - TiteliveBookSearch().synchronize_products(from_date.date() if from_date else None, from_page) +def synchronize_titelive_book_products( + from_date: datetime.datetime | None, to_date: datetime.datetime | None, from_page: int +) -> None: + TiteliveBookSearch().synchronize_products( + from_date.date() if from_date else None, to_date.date() if to_date else None, from_page + )