Ejemplo n.º 1
0
def create_reactivation_emails(date_from=None, date_to=None):
    # select users who became inactive N days ago
    listid = app.config.get('REACTIVATION_EMAIL_LISTID', 1)
    delta = timedelta(days=app.config.get('REACTIVATION_THRESHOLD_DAYS', 7))
    window = [d - delta for d in date_from, date_to]
    inactivity_window = UserAccountEvent.query.group_by(UserAccountEvent.user).\
        having(func.max(UserAccountEvent.event_date).between(*window)).\
        with_entities(UserAccountEvent.user)
    excluded_users = UserFlag.query.filter(
        UserFlag.flag.in_(('bouncing', 'unsub%d' % listid))).with_entities(UserFlag.user)
    inactive_users = User.query.filter(
        User.is_active == True,
        User.email != '',
        User.id.in_(inactivity_window),
        User.id.notin_(excluded_users))

    tracking_params = app.config.get('REACTIVATION_EMAIL_TRACKING_PARAMS')
    with url_tracking_context(tracking_params):
        template = email.env.get_template('reactivation.html')
        for user in inactive_users:
            ctx = _reactivation_feed_context(user, window[0])
            if ctx:
                ctx.update(
                    unsubscribe_token=create_unsubscribe_token(listid, user.id),
                    **tracking_params
                )
                _send_email_or_log(user, template, **ctx)
Ejemplo n.º 2
0
def create_ping_emails(listid, template_path, threshold_days, tracking_params, date_from=None, date_to=None):
    delta = timedelta(days=threshold_days)
    window = [d - delta for d in date_from, date_to]
    excluded_users = UserFlag.query.filter(
        UserFlag.flag.in_(('bouncing', 'unsub%d' % listid))).with_entities(UserFlag.user)
    users = User.query.filter(
        User.is_active == True,
        User.email != '',
        User.date_joined.between(*window),
        User.id.notin_(excluded_users))

    with url_tracking_context(tracking_params):
        template = email.env.get_template(template_path)
        for user in users:
            ctx = dict(
                unsubscribe_token=create_unsubscribe_token(listid, user.id),
                **tracking_params
            )
            _send_email_or_log(user, template, **ctx)
Ejemplo n.º 3
0
def influencer_starred_email(recipient, sender, influencer_id, video_instance):
    if recipient.id in (sender.id, influencer_id):
        return

    listid = app.config.get('RECOMMENDATION_EMAIL_LISTID', 2)
    if any(f for f in recipient.flags if f.flag in ('bouncing', 'unsub%d' % listid)):
        return

    influencer = User.query.get(influencer_id)
    link = ShareLink.get_or_create(sender.id, 'video_instance', video_instance.id)[0]
    ctx = dict(
        sender=sender,
        link=link,
        object_type='video_instance',
        object_type_name='video',
        object=video_instance,
        senders=[sender, influencer],
        unsubscribe_token=create_unsubscribe_token(listid, recipient.id)
    )
    tracking_params = app.config.get('RECOMMENDATION_EMAIL_TRACKING_PARAMS')
    with url_tracking_context(tracking_params):
        template = email.env.get_template('video_recommendation.html')
        _send_email_or_log(recipient, template, **ctx)