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

unsubscribe daily email people if they haven't read in the last 30 days #7077

Merged
merged 10 commits into from
Jul 28, 2020
57 changes: 57 additions & 0 deletions app/marketing/management/commands/unsubscribe_daily_emails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
"""Define the GDPR reconsent command for EU users.

Copyright (C) 2020 Gitcoin Core

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

"""
import time
import warnings

from django.core.management.base import BaseCommand
from django.conf import settings
from django.utils import timezone
from marketing.mails import gdpr_reconsent
from marketing.models import EmailSubscriber, EmailEvent
from marketing.utils import should_suppress_notification_email

warnings.filterwarnings("ignore", category=DeprecationWarning)


class Command(BaseCommand):

help = 'unsubscribes people from their daily emails if they are not reading them, per https://gitcoincore.slack.com/archives/CB1N0L6F7/p1594141095159400'

def handle(self, *args, **options):
days = 90 if settings.DEBUG else 30
time_threshold = timezone.now() - timezone.timedelta(days=days)
eses = EmailSubscriber.objects.order_by('-created_on')
email_type_sendgrid = "new_bounty_daily"
email_type_settings = 'new_bounty_notifications'
for es in eses:
if not should_suppress_notification_email(es.email, email_type_settings):
base_email_events = EmailEvent.objects.filter(email=es.email, created_on__gt=time_threshold, category__icontains=email_type_sendgrid)
num_sends = base_email_events.filter(event='delivered').count()
num_opens = base_email_events.filter(event='open').count()
num_clicks = base_email_events.filter(event='click').count()

do_unsubscribe = num_sends > 5 and num_opens < 1 and num_clicks < 1
if do_unsubscribe:
unsubscribed_email_type = {}
unsubscribed_email_type[email_type_settings] = True
es.build_email_preferences(unsubscribed_email_type)
print(f"unsubscribed {es.email} {num_clicks} {num_opens} {num_clicks}")
es.save()

1 change: 1 addition & 0 deletions scripts/crontab
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/us
15 1 * * * cd gitcoin/coin; bash scripts/run_management_command.bash sync_keywords >> /var/log/gitcoin/sync_keywords.log 2>&1
# 40 */3 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash sync_slack >> /var/log/gitcoin/sync_slack.log 2>&1
30 1 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash sync_github >> /var/log/gitcoin/sync_github.log 2>&1
30 1 1,15 * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash unsubscribe_daily_emails >> /var/log/gitcoin/unsubscribe_daily_emails.log 2>&1
*/15 * * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash get_notifications >> /var/log/gitcoin/get_notifications.log 2>&1
15 10 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash bounty_feedback_email >> /var/log/gitcoin/bounty_feedback_email.log 2>&1
15 10 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash funder_stale_email 60 >> /var/log/gitcoin/funder_stale_email.log 2>&1
Expand Down