Esempio n. 1
0
def update_contacts(user_id, p_contacts):
    logger.warning('update_contacts user_id:%s numbers:%s' % (user_id, str(p_contacts)))
    u_ph = col_get(USERPHONE, {"user_id" : user_id}, find='one')
    if u_ph:
        logger.warning('update_contacts user_id:%s removing existing user store' % (user_id))
        col_remove(USERPHONE, {"user_id" : user_id})
    
    new_u_ph = {'user_id' : user_id, 'contacts' : p_contacts}
    logger.warning('update_contacts user_id:%s adding user store' % (user_id))
    nid = col_insert(USERPHONE, new_u_ph)
    return True
Esempio n. 2
0
def invite_numbers(user_id, numbers, aid, send_sms = True):
    logger.warning('invite_numbers user_id:%s numbers:%s aid:%s' % (user_id, str(numbers), str(aid)))
    user = col_get(USER_, {"_id" : user_id}, find='one')
    himher = 'him' if user.get('gender') == 'male' else 'her'
    invitees = []
    sms_details = []
    if aid:
        activity = col_get(ACTIVITY_, {'_id' : ObjectId(aid)}, find='one')
    else:
        aid = ''
    for number in numbers:
        hash_ = get_b64_hash(number)
        link = 'http://keen.to/invite/%s' % hash_
        if aid:
            msg = '%s has invited you to join %s for #%s, follow the link %s' % (user.get('first_name').title(), himher, activity.get('keyword'), link)
        else:
            msg = "%s has invited you to Keen! Join %s at %s" % (user.get('first_name').title(), himher, link)
        invitees.append({'hashid' : hash_, 'number' : number, 'click_link' : False, 'signup' : False, 'aid' : aid})
        sms_details.append((number, msg))
    
    existing_invite = col_get(INVITES, {"inviter_id" : user_id}, find='one')
    if existing_invite:
        col_update(INVITES, {"inviter_id" : user_id}, {"$pushAll" : { "invitees" : invitees }})
        db_op = 'update: pushAll %s' % str(invitees)
    else:
        new_invite = {'inviter_id' : user_id, 'invitees' : invitees}
        inv_id = col_insert(INVITES, new_invite)
        db_op = 'insert: %s new_invite:%s' % (str(inv_id), new_invite)
    logger.warning('invite_numbers user_id:%s db_op:%s' % (user_id, db_op))
    #Do the sending last, just to make sure everythings in place for the click response to be tracked
    if send_sms:
        for number, msg in sms_details:
            try:
                result = send_sms(number, msg)
                logger.warning('invite_numbers user_id:%s send_sms number:%s msg:%s result:%s' % (user_id, str(number), str(msg), str(result)))
            except Exception, e:
                logger.warning('invite_numbers user_id:%s send_sms number:%s msg:%s EXCEPTION:%s' % (user_id, str(number), str(msg), str(e)))
Esempio n. 3
0
def add_competition_entry(user_id, value):
    logger.warning('add_competition_entry user_id:%s value:%s' % (str(user_id), str(value)))
    u = col_get(USER_, {"_id" : user_id}, find='one')
    now = datetime.datetime.now()
    entry = {
        'value' : value,
        'when'  : now         
    }
    if u.get('network') != settings.OTAGO:
        logger.warning('add_competition_entry user_id:%s entry:%s u.network:%s is no UoOtago' % (str(user_id), str(entry), u.get('network')))
        return
    comp = col_get(COMPETITION, {"user_id" : user_id}, {}, 'one')
    if comp:
        #Push to comp
        logger.warning('add_competition_entry user_id:%s comp exists pushing entry' % str(user_id))
        col_update(COMPETITION, {"user_id" : user_id}, {'$push' : {'entries' : entry}})
    else:
        new_comp = {
            'user_id' : user_id,
            'entries' : [entry]
        }
        logger.warning('add_competition_entry user_id:%s new_comp:%s' % (str(user_id), str(new_comp)))
        c_id = col_insert(COMPETITION, new_comp)
    notification_tasks.send_admin_notification(user_id, "Score! You've got another entry to #partylikeaboss", 'One more chance to #partylikeaboss')