コード例 #1
0
def send_unique_push_message(recipient_user, message, type, sending_user):
    # if settings.ENVIRONMENT and settings.ENVIRONMENT == 'Production':
    send_hotspot_message(users=[recipient_user],
                         push_text=message,
                         message_type=MESSAGE_TYPE.GENERAL)
    track_notification(recipient_user, NOTIFICATION_TYPE.FRIEND_JOINED_PUSH,
                       message, sending_user)
コード例 #2
0
def send_winback_drinks(lat=47.667759,
                        lng=-122.312766,
                        distance=20,
                        now=datetime.now()):
    users = get_user_within_distance(lat, lng, distance)
    old_users = users.filter(date_joined__lt=now - timedelta(weeks=2))
    venues = get_venues_within_distance(lat, lng, distance)
    deals = Deal.objects.filter(place__in=venues,
                                active=True,
                                in_app_payment=True)
    excluded_beacons = Beacon.objects.filter(creator_id__in=excluded_users)
    hotspot_ids = DealStatus.objects.filter(deal__in=deals).values_list(
        'beacon_id', flat=True).distinct().exclude(beacon__in=excluded_beacons)
    hotspots = Beacon.objects.filter(pk__in=hotspot_ids).exclude(
        cancelled=True)
    paid_deal_statuses = DealStatus.objects.filter(beacon__in=hotspots)
    paid_redemptions = paid_deal_statuses.filter(
        deal_status=DEAL_STATUS.REDEEMED).exclude(
            payment_authorization="REWARD")
    reward_redemptions = paid_deal_statuses.filter(
        payment_authorization="REWARD", deal_status=DEAL_STATUS.REDEEMED)
    count = 0
    for user in old_users:
        if not RewardItem.objects.filter(user=user).exists():
            if not paid_redemptions.filter(
                    user=user).exists() and not reward_redemptions.filter(
                        user=user).exists():
                reward_item = RewardItem(user=user)
                reward_item.date_expired = datetime.now() + timedelta(days=31)
                reward_item.save()
                send_winback_email(user)
                track_notification(user, NOTIFICATION_TYPE.WINBACK_EMAIL)
                print "Winback drink sent to: " + user.email
コード例 #3
0
def send_background_deal_notification(user, deal):
    message = "Nearby Offer: Get a {0} for ${1} at {2}".replace(
        "{0}", deal.item_name.lower()).replace("{1}", str(int(
            deal.item_price))).replace("{2}", deal.place.name)
    send_hotspot_push([user], message)
    track_notification(user, NOTIFICATION_TYPE.BACKGROUND_NOTIFICATION,
                       deal.id)
コード例 #4
0
def tickets_are_live_push_notifications(is_test=True):
    markets = Market.objects.all()
    upcoming_events = []
    for market in markets:
        event = get_next_event_in_market(market)
        if event and not PushCampaignTracker.objects.filter(
                type=PUSH_CAMPAIGN_TYPE.TICKETS_LIVE, event=event).exists():
            upcoming_events.append(event)
    for event in upcoming_events:
        body = "Tickets are now live for the {0} at {1}. There are a limited number available for ${2} so reserve yours soon!".format(
            event.item_name.lower(), event.place.name,
            int(event.presale_item_price))
        if is_test:
            print event.place.name
            user = User.objects.get(username="******")
            send_hotspot_push([user], body, None, None, None, event.id)
        else:
            all_users = get_user_within_distance(event.place.latitude,
                                                 event.place.longitude)
            users_ids_to_exclude = EventStatus.objects.filter(
                event=event, status="U").values_list('user', flat=True)
            users = all_users.exclude(pk__in=users_ids_to_exclude)
            print "Event: " + event.place.name + " " + str(len(users))
            count = 0
            for user in users:
                send_hotspot_push([user], body, None, None, None, event.id)
                track_notification(user, "DP", body)
                count += 1
            push_campaign = PushCampaignTracker(
                event=event,
                message=body,
                total_sent=count,
                type=PUSH_CAMPAIGN_TYPE.TICKETS_LIVE)
            push_campaign.save()
コード例 #5
0
def send_notification(invited_user, message, sending_user):
    # users_to_invite = get_users_to_invite(user, lat, lng)
    # for invited_user in users_to_invite:
    send_hotspot_push([invited_user], message)
    track_notification(invited_user, NOTIFICATION_TYPE.FRIEND_INVITED_PUSH,
                       message, sending_user)
    print sending_user.get_full_name()
    print message
    print ""
コード例 #6
0
def send_saw_picture_notification(deal_status, friend_who_saw_picture):
    message = "{0} saw your picture at {1}".format(
        friend_who_saw_picture.get_full_name(), deal_status.deal.place.name)
    send_hotspot_message([deal_status.user],
                         message,
                         message_type=MESSAGE_TYPE.GENERAL,
                         silent=True)
    track_notification(deal_status.user, NOTIFICATION_TYPE.IMAGE_SEEN, message,
                       friend_who_saw_picture)
コード例 #7
0
def send_image_notification(deal_status, sending_user):
    message = "{0} added a picture at {1}".format(sending_user.first_name,
                                                  deal_status.deal.place.name)
    user_ids, blocked_user_ids = get_friends(sending_user)
    users = User.objects.filter(pk__in=user_ids)
    for user in users:
        send_hotspot_message([user],
                             message,
                             message_type=MESSAGE_TYPE.NEWSFEED,
                             silent=True)
        track_notification(user, NOTIFICATION_TYPE.IMAGE_ADDED, message,
                           sending_user)
コード例 #8
0
def send_individual_push_for_tickets_live():
    campaigns = EmailCampaignTracker.objects.filter(
        type=EMAIL_CAMPAIGN_TYPE.TICKETS_LIVE,
        date_sent__gte=datetime.now() - timedelta(days=3),
        user__isnull=False)
    for campaign in campaigns:
        user = campaign.user
        event = campaign.event
        body = "Tickets are now live for the {0} at {1}. There are a limited number available for ${2} so reserve yours soon!".format(
            event.item_name.lower(), event.place.name,
            int(event.presale_item_price))
        send_hotspot_push([user], body, None, None, None, event.id)
        track_notification(user, "DP", body)
コード例 #9
0
def free_drink_retention_push(min_date=datetime.now() - timedelta(weeks=1),
                              max_date=datetime.now()):
    users_in_seattle = get_user_within_distance(47.667759, -122.312766, 20)
    active_users = Location.objects.filter(
        date_created__gte=min_date,
        date_created__lt=max_date,
        user__in=users_in_seattle).values_list('user', flat=True).distinct()
    inactive_users_with_free_drinks_ids = RewardItem.objects.filter(
        isRedeemed=False,
        reward_type=REWARD_TYPES.DRINK,
        user__in=users_in_seattle).exclude(
            user_id__in=active_users).values_list("user_id", flat=True)
    inactive_users_with_free_drinks = User.objects.filter(
        pk__in=inactive_users_with_free_drinks_ids)
    message = "You still have a free drink waiting on Hotspot. Redeem it soon!"
    for user in inactive_users_with_free_drinks:
        send_hotspot_push([user], message)
        track_notification(user, NOTIFICATION_TYPE.FREE_DRINK_REMINDER_PUSH)