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)
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()
def send_push_notifications_to_event_attendees(message, sponsored_event): event_attendee_ids = EventStatus.objects.filter( status="R", event=sponsored_event).values_list('user', flat=True) users = User.objects.filter(pk__in=event_attendee_ids) for user in users: send_hotspot_push([user], message, None, None, None, sponsored_event.id)
def save_match_selection(user, request_data): if 'dating_profile_id' and 'is_selected' and 'event_id' not in request_data: return False dating_profile_selector = DatingProfile.objects.get( dating_profile=user.profile) dating_profile_selectee = DatingProfile.objects.get( pk=request_data['dating_profile_id']) is_selected = int(request_data['is_selected']) print "IS SELECTED: + " + str(is_selected) event_id = request_data['event_id'] event = SponsoredEvent.objects.get(pk=event_id) if DatingMatch.objects.filter( dating_profile_selector=dating_profile_selector, dating_profile_selectee=dating_profile_selectee, event=event).exists(): dating_match = DatingMatch.objects.get( dating_profile_selector=dating_profile_selector, dating_profile_selectee=dating_profile_selectee, event=event) dating_match.is_selected = is_selected else: dating_match = DatingMatch( dating_profile_selector=dating_profile_selector, dating_profile_selectee=dating_profile_selectee, is_selected=is_selected, event=event) dating_match.save() if is_selected: if DatingMatch.objects.filter( dating_profile_selector=dating_profile_selectee, dating_profile_selectee=dating_profile_selector, event=event, is_selected=True).exists(): current_user = dating_profile_selector.dating_profile.user other_user = dating_profile_selectee.dating_profile.user message = "You matched with {0} for the event at {1}".replace( "{0}", current_user.get_full_name()).replace("{1}", event.place.name) send_hotspot_push([other_user], message) try: create_sms_thread(current_user, other_user, event) except: # send_error_report_email("Chat Line Failed", []) print "SMS Thread Failed to Create" return [dating_profile_selectee] elif DatingMatch.objects.filter( dating_profile_selector=dating_profile_selectee, dating_profile_selectee=dating_profile_selector, event=event, is_selected=False).exists(): return [] else: user = dating_profile_selectee.dating_profile.user message = "Someone who's also going to the event at {0} just liked you on 'Swipe & Match'".replace( "{0}", event.place.name) send_hotspot_push([user], message) return [] else: return []
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 ""
def send_arrival_push(): event_statuses = EventStatus.objects.filter(arrival_message_sent=False, status=EVENT_STATUS.REDEEMED) for status in event_statuses: welcome_message = "Welcome to the event! If you wanna mingle, check out 'Swipe & Match' to meet people at the event!" send_hotspot_push([status.user], welcome_message, "EventChat", None, None, status.event.id) status.arrival_message_sent = True status.save()
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)
def send_notification_for_event(invited_user, message, sending_user, event): # users_to_invite = get_users_to_invite(user, lat, lng) # for invited_user in users_to_invite: send_hotspot_push([invited_user], message) notification_tracker = NotificationTracker( recipient=invited_user, notification_type=NOTIFICATION_TYPE.EVENT_RESERVED_PUSH, notification_detail=message, sender=sending_user, event=event) notification_tracker.save() print sending_user.get_full_name() print message print ""
def send_friends_message(users_with_friends, event): for user in users_with_friends: friend_ids = Friendship.objects.filter(user=user).values_list( 'friend', flat=True) event_statuses = EventStatus.objects.filter(user_id__in=friend_ids, status=EVENT_STATUS.GOING) if len(event_statuses) > 1: message = "{0} friends are going to the open bar tomorrow at {1}. The presale ends today - make sure to reserve your ticket soon!".replace( "{0}", str(len(event_statuses))).replace("{1}", event.place.name) else: message = "{0} friend is going to the open bar tomorrow at {1}. The presale ends today - make sure to reserve your ticket soon!".replace( "{0}", str(len(event_statuses))).replace("{1}", event.place.name) send_hotspot_push([user], message)
def check_for_dating_queue(): events = SponsoredEvent.objects.filter(end__gte=datetime.now()) dating_profile_ids = DatingProfile.objects.all().values_list( 'dating_profile', flat=True) user_ids = Profile.objects.filter(pk__in=dating_profile_ids).values_list( 'user', flat=True) filtered_event_statuses = EventStatus.objects.filter( user_id__in=user_ids, event__in=events, status=EVENT_STATUS.GOING) for event_status in filtered_event_statuses: user = event_status.user event = event_status.event dating_queue = get_dating_queue(user, event.id) if len(dating_queue) > 0: message = "You have new people to swipe through who are going to the event at {0}!".replace( "{0}", event.place.name) send_hotspot_push([user], message)
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)
def send_notifications(users, push_message, event): for user in users: send_hotspot_push([user], push_message, "EventChat", None, None, event.id)
def send_regular_push_message(users_without_friends, event): for user in users_without_friends: message = "The presale ends today for the open bar tomorrow at {0}. Make sure to reserve your ticket soon!".replace( "{0}", event.place.name) send_hotspot_push([user], message)