Skip to content

Commit

Permalink
(BSR)[API] fix: titelive sync commands call
Browse files Browse the repository at this point in the history
  • Loading branch information
dnguyen1-pass committed Jan 3, 2025
1 parent af86f8a commit 3db68cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
4 changes: 1 addition & 3 deletions api/src/pcapi/core/providers/titelive_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 24 additions & 4 deletions api/src/pcapi/scheduled_tasks/titelive_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand All @@ -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",
Expand All @@ -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
)

0 comments on commit 3db68cd

Please sign in to comment.