Skip to content

Commit

Permalink
(PC-31833)[API] feat: pro(marketing): update (new) contacts lists
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremieb-pass committed Oct 21, 2024
1 parent ecad854 commit 573f00a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/src/pcapi/connectors/big_query/queries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
from .favorites_not_booked import FavoritesNotBooked # noqa: F401
from .favorites_not_booked import FavoritesNotBookedModel # noqa: F401
from .last_30_days_booking import Last30DaysBookings # noqa: F401
from .marketing import ProLiveShowEmailChurned40DaysAgoQuery
from .marketing import ProLiveShowEmailLastBooking40DaysAgoQuery
from .pro_email_churned_40_days_ago import ChurnedProEmail # noqa: F401
from .pro_no_bookings_since_40_days_ago import NoBookingsProEmail # noqa: F401
39 changes: 39 additions & 0 deletions api/src/pcapi/connectors/big_query/queries/marketing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pydantic.v1 as pydantic_v1

from pcapi import settings

from .base import BaseQuery


class ProLiveShowEmailChurned40DaysAgoModel(pydantic_v1.BaseModel):
venue_booking_email: int | None


class ProLiveShowEmailChurned40DaysAgoQuery(BaseQuery):
raw_query = f"""
select
distinct venue_booking_email
from
`{settings.BIG_QUERY_TABLE_BASENAME}.marketing_pro_live_show_email_churned_40_days_ago`
where
cast(execution_date as date) = current_date()
"""

model = ProLiveShowEmailChurned40DaysAgoModel


class ProLiveShowEmailLastBooking40DaysAgoModel(pydantic_v1.BaseModel):
venue_booking_email: int | None


class ProLiveShowEmailLastBooking40DaysAgoQuery(BaseQuery):
raw_query = f"""
select
distinct venue_booking_email
from
`{settings.BIG_QUERY_TABLE_BASENAME}.marketing_pro_live_show_email_last_booking_40_days_ago`
where
cast(execution_date as date) = current_date()
"""

model = ProLiveShowEmailLastBooking40DaysAgoModel
14 changes: 14 additions & 0 deletions api/src/pcapi/core/external/automations/pro_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ def pro_no_bookings_since_40_days_automation() -> bool:
return add_contacts_to_list(
no_bookings_pro_emails, settings.SENDINBLUE_PRO_NO_BOOKINGS_40_DAYS_ID, use_pro_subaccount=True
)


def update_pro_contacts_list_for_live_show_churned_40_days_ago() -> bool:
email = [row.venue_booking_email for row in big_queries.ProLiveShowEmailChurned40DaysAgoQuery().execute()]
return add_contacts_to_list(
email, settings.SENDINBLUE_PRO_MARKETING_LIVE_SHOW_EMAIL_CHURNED_40_DAYS_AGO, use_pro_subaccount=True
)


def update_pro_contacts_list_for_live_show_last_booking_40_days_ago() -> bool:
email = [row.venue_booking_email for row in big_queries.ProLiveShowEmailLastBooking40DaysAgoQuery().execute()]
return add_contacts_to_list(
email, settings.SENDINBLUE_PRO_MARKETING_LIVE_SHOW_EMAIL_LAST_BOOKING_40_DAYS_AGO, use_pro_subaccount=True
)
12 changes: 12 additions & 0 deletions api/src/pcapi/scheduled_tasks/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ def pro_no_bookings_since_40_days_automation() -> None:
pro_user_automations.pro_no_bookings_since_40_days_automation()


@blueprint.cli.command("pro_marketing_live_show_email_churned_40_days_ago")
@log_cron_with_transaction
def pro_marketing_live_show_email_churned_40_days_ago() -> None:
pro_user_automations.update_pro_contacts_list_for_live_show_churned_40_days_ago()


@blueprint.cli.command("pro_marketing_live_show_email_last_booking_40_days_ago")
@log_cron_with_transaction
def pro_marketing_live_show_email_last_booking_40_days_ago() -> None:
pro_user_automations.update_pro_contacts_list_for_live_show_last_booking_40_days_ago()


@blueprint.cli.command("notify_users_bookings_not_retrieved")
@log_cron_with_transaction
def notify_users_bookings_not_retrieved_command() -> None:
Expand Down
6 changes: 6 additions & 0 deletions api/src/pcapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@
SENDINBLUE_PRO_INACTIVE_90_DAYS_ID = int(os.environ.get("SENDINBLUE_PRO_INACTIVE_90_DAYS_ID", 35))
SENDINBLUE_PRO_NO_ACTIVE_OFFERS_40_DAYS_ID = int(os.environ.get("SENDINBLUE_PRO_NO_ACTIVE_OFFERS_40_DAYS_ID", 545))
SENDINBLUE_PRO_NO_BOOKINGS_40_DAYS_ID = int(os.environ.get("SENDINBLUE_PRO_NO_BOOKINGS_40_DAYS_ID", 558))
SENDINBLUE_PRO_MARKETING_LIVE_SHOW_EMAIL_CHURNED_40_DAYS_AGO = int(
os.environ.get("SENDINBLUE_PRO_MARKETING_LIVE_SHOW_EMAIL_CHURNED_40_DAYS_AGO", 688)
)
SENDINBLUE_PRO_MARKETING_LIVE_SHOW_EMAIL_LAST_BOOKING_40_DAYS_AGO = int(
os.environ.get("SENDINBLUE_PRO_MARKETING_LIVE_SHOW_EMAIL_LAST_BOOKING_40_DAYS_AGO", 687)
)

# RECAPTCHA
RECAPTCHA_MINIMAL_SCORE = float(os.environ.get("RECAPTCHA_RESET_PASSWORD_MINIMAL_SCORE", 0.7))
Expand Down

0 comments on commit 573f00a

Please sign in to comment.