Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-33815)[API] fix: titelive sync commands call #15712

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
Loading