Beispiel #1
0
def send_recommendation_notification(user):
    if not user.ios_devices.exists() and not user.android_devices.exists():
        return

    message = smart_format(
        "Hey {0}! Looking to get friends together tonight? Set a hotspot.",
        user.first_name)
    foursquare_id = None
    bar = get_nearby_bar_for_user(user)
    if bar:
        name = bar['name']
        foursquare_id = bar['id']
        location_data = bar['location']
        location = None
        if 'crossStreet' in location_data.keys():
            location = location_data['crossStreet']
        elif 'address' in location_data.keys():
            location = location_data['address']
        if location:
            message = smart_format(
                "Hey {0}! Looking to get friends together tonight? Set a hotspot at {1} ({2}). It's heating up!",
                user.first_name, name, location)
        else:
            message = smart_format(
                "Hey {0}! Looking to get friends together tonight? Set a hotspot at {1}. It's heating up!",
                user.first_name, name)
    recommendation = Recommendation.objects.create(
        user=user, foursquare_venue_id=foursquare_id, message_text=message)
    send_hotspot_message([user],
                         push_text=message,
                         message_type=MESSAGE_TYPE.HOTSPOT_RECOMMENDATION,
                         recommendation_id=recommendation.pk)
Beispiel #2
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)
Beispiel #3
0
def send_reminder(beacon):
    #usually queued on scheduler, so refresh object
    beacon = refetch_model_instance(beacon)
    if beacon.cancelled:
        return
    beacon_follows = BeaconFollow.objects.filter(beacon=beacon).exclude(state=BEACON_FOLLOW_STATUS.DECLINED).\
        select_related('user', 'contact')
    time_string = DateFormatter().friendly_string_for_timestamp(
        beacon.beacon_time, beacon.latitude, beacon.longitude)
    text = smart_format("Reminder: {0}\n{1} @ {2}", beacon.description,
                        time_string, beacon.address)
    users = []
    contacts = []
    for b in beacon_follows:
        if b.user:
            users.append(b.user)
        else:
            contacts.append(b.contact)
    #        for now message type is MESSAGE in order to open to correct hotspot
    send_hotspot_message(users=users,
                         push_text=text,
                         contacts=contacts,
                         sms_text=text,
                         message_type=MESSAGE_TYPE.MESSAGE,
                         beacon_id=beacon.pk)
Beispiel #4
0
def send_hotspot_push_to_correct_profiles(beacon,
                                          push_message,
                                          message_type=None):
    users = users_to_notify(beacon, message_type=message_type)
    send_hotspot_message(users=users,
                         push_text=push_message,
                         message_type=MESSAGE_TYPE.MESSAGE,
                         beacon_id=beacon.id)
Beispiel #5
0
def invite_friends(user, beacon, invite_list, message=None):
    if DealStatus.objects.filter(beacon=beacon).exists():
        deal_status = DealStatus.objects.filter(beacon=beacon, user=user)[0]
        deal_id = deal_status.deal.id
        deal = Deal.objects.get(pk=deal_id)
        #beacon_datetime = datetime.datetime.fromtimestamp(timestamp)
        # deal = Deal.objects.select_related('place').get(pk=deal_id)
        # place = deal.place
        # description = smart_format("Deal at {0}", place.name)

        #get deal hours
        timezone = GeoTimeZone().get_timezone(latitude=beacon.latitude, longitude=beacon.longitude)
        timestamp = calendar.timegm(deal_status.start.timetuple())
        beacon_datetime = datetime.datetime.fromtimestamp(timestamp, tz=timezone)
        # beacon_datetime = deal_status.start
        today_time = 60*60*beacon_datetime.hour + 60*beacon_datetime.minute + beacon_datetime.second

        deal_hours = deal_hours_for_datetime(deal, beacon.time)
        # start = beacon_datetime + datetime.timedelta(seconds=deal_hours.start - today_time)
        start = deal_status.start
        end = deal_status.end
        #create deal status and beacon status objects
        user_list, contact_list = parse_json_into_users_and_contact_lists(user, invite_list)
        beacon_follows = []
        deal_statuses = []
        cleaned_contact_list = remove_duplicate_contacts(contact_list)
        #create deal status and beacon follow for creator
        # deal_statuses.append(DealStatus(deal=deal, beacon=beacon, user=user, hours=deal_hours, start=start, end=end))
        # beacon_follows.append(BeaconFollow(beacon=beacon, user=user, state=BEACON_FOLLOW_STATUS.GOING))
        for invited_user in user_list:
            deal_statuses.append(DealStatus(deal=deal, beacon=beacon, user=invited_user, invited_by=user, hours=deal_hours, start=start, end=end))
            beacon_follows.append(BeaconFollow(beacon=beacon, user=invited_user, invited_by=user))
        for invited_contact in cleaned_contact_list:
            deal_statuses.append(DealStatus(deal=deal, beacon=beacon, contact=invited_contact, invited_by=user, hours=deal_hours, start=start, end=end))
            beacon_follows.append(BeaconFollow(beacon=beacon, contact=invited_contact, invited_by=user))
        BeaconFollow.objects.bulk_create(beacon_follows)
        DealStatus.objects.bulk_create(deal_statuses)
        update_deal_statuses_for_beacon(beacon, deal)

        #send invitations
        if message is None:
            send_deal_invites.delay(deal_statuses, beacon.custom_deal_message)
        else:
            send_deal_invites.delay(deal_statuses, message, user)
        return True
    else:
        # invite more people to this Beacon if the new follower included an invite list
        user_list, contact_list = parse_json_into_users_and_contact_lists(user, invite_list)
        numberOfInvites = len(user_list) + len(contact_list)
        if numberOfInvites > 0:
            send_sms_invites(user, beacon, user_list, contact_list)
            chat_message, avatar_url = invite_friends_message(user, numberOfInvites)
            if beacon.creator != user:
                send_hotspot_message(users=[beacon.creator], push_text=chat_message,
                                     message_type=MESSAGE_TYPE.HOTSPOT_UPDATE, beacon_id=beacon.id)
            create_hotspot_message_in_chat(beacon, chat_message, user, None, avatar_url)
        return True
Beispiel #6
0
def send_reminder_message(host, invitee, amount):
    float_amount = "%0.2f" % amount
    message = "Please remember to repay {0} ${1}".format(
        host.first_name, float_amount)
    send_hotspot_message([invitee], message, [], message)