From 43a021dd885e1c19cdf7ebfdb499280c942d8f6a Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 13 Dec 2020 19:18:58 +0100 Subject: [PATCH] send a reminder when a coinbase subscription is ending soon --- cron.py | 39 ++++++++++++++++++- .../coinbase/reminder-subscription.html | 18 +++++++++ .../coinbase/reminder-subscription.txt | 7 ++++ tests/test_cron.py | 19 +++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 templates/emails/transactional/coinbase/reminder-subscription.html create mode 100644 templates/emails/transactional/coinbase/reminder-subscription.txt create mode 100644 tests/test_cron.py diff --git a/cron.py b/cron.py index fc54e957..e07d5790 100644 --- a/cron.py +++ b/cron.py @@ -42,6 +42,7 @@ from app.models import ( Mailbox, Monitoring, Contact, + CoinbaseSubscription, ) from server import create_app @@ -114,7 +115,7 @@ def notify_manual_sub_end(): LOG.debug("Remind user %s that their manual sub is ending soon", user) send_email( user.email, - f"Your trial will end soon {user.name}", + f"Your subscription will end soon {user.name}", render( "transactional/manual-subscription-end.txt", name=user.name, @@ -129,6 +130,42 @@ def notify_manual_sub_end(): ), ) + extend_subscription_url = URL + "/dashboard/extend_subscription" + for coinbase_subscription in CoinbaseSubscription.query.all(): + need_reminder = False + if ( + arrow.now().shift(days=14) + > coinbase_subscription.end_at + > arrow.now().shift(days=13) + ): + need_reminder = True + elif ( + arrow.now().shift(days=4) + > coinbase_subscription.end_at + > arrow.now().shift(days=3) + ): + need_reminder = True + + if need_reminder: + user = coinbase_subscription.user + LOG.debug( + "Remind user %s that their coinbase subscription is ending soon", user + ) + send_email( + user.email, + f"Your SimpleLogin subscription will end soon", + render( + "transactional/coinbase/reminder-subscription.txt", + coinbase_subscription=coinbase_subscription, + extend_subscription_url=extend_subscription_url, + ), + render( + "transactional/coinbase/reminder-subscription.html", + coinbase_subscription=coinbase_subscription, + extend_subscription_url=extend_subscription_url, + ), + ) + def poll_apple_subscription(): """Poll Apple API to update AppleSubscription""" diff --git a/templates/emails/transactional/coinbase/reminder-subscription.html b/templates/emails/transactional/coinbase/reminder-subscription.html new file mode 100644 index 00000000..b02d0369 --- /dev/null +++ b/templates/emails/transactional/coinbase/reminder-subscription.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} + +{% block content %} + {% call text() %} +