コード例 #1
0
def add_keener_notification(user_id, aid, keener_id):
    aid = str(aid)
    user = col_get(USER_, {"_id" : user_id}, find='one')
    watch_notifs = user.get('watch_notifs', {})
    if aid in watch_notifs.keys():
        watch_notifs[aid]['k'] = watch_notifs[aid]['k'] + 1
    else:
        watch_notifs[aid] = {'c' : 0, 'k' : 1}
    col_update(USER_, {'_id' : user_id}, {'$set' : {'watch_notifs' : watch_notifs}})
コード例 #2
0
def add_comment_nofification(user_ids, aid):
    aid = str(aid)
    for user_id in user_ids:
        user = col_get(USER_, {"_id" : user_id}, find='one')
        watch_notifs = user.get('watch_notifs', {})
        if aid in watch_notifs.keys():
            watch_notifs[aid]['c'] = watch_notifs[aid]['c'] + 1
        else:
            watch_notifs[aid] = {'c' : 1, 'k' : 0}
        col_update(USER_, {'_id' : user_id}, {'$set' : {'watch_notifs' : watch_notifs}})
コード例 #3
0
ファイル: tasks.py プロジェクト: pchennz/KEEN-full
def save_mutual_relations(user_id, rms, friends, fofs):
    """
    Saves the mutual relations into the mongodb datastore
    The rms (relation mutuals) are expected to be accurate, by default relations will be taken as 'friends' or 'fofs'
    """
    logger.warning('save_mutual_relations user_id:%s' % str(user_id))
    d = {}
    fs = []
    for f_id, friend in friends.iteritems():
        mutuals = friend.get('mutuals')
        d[f_id] = settings.RELATION_FRIEND, mutuals
        fs.append({'fb_id' : f_id, 'mutuals' : len(mutuals), 'relation' : settings.RELATION_FRIEND})
    
    s_fofs = []
    for fof_id, fof in fofs.iteritems():
        mutuals = fof.get('mutuals')
        d[fof_id] = settings.RELATION_FOF, mutuals
        s_fofs.append({'fb_id' : f_id, 'mutuals' : len(mutuals), 'relation' : settings.RELATION_FOF})
    
    for key, val in rms.iteritems():
        d[key] = val
    
#    logger.warning('save_mutual_relations user_id:%s d:%s' % (str(user_id), str(d)))
    col_update(MUTUALRELATION, {'user_id' : user_id}, {'$set' : {'mutual_relations' : d}}, upsert=True)
    col_update(FRIENDSTORE_, {'user_id' : user_id}, {'$set' : {'friends' : fs}}, upsert=True)
    col_update(FOFSTORE_, {'user_id' : user_id}, {'$set' : {'friend_of_friends' : s_fofs}}, upsert=True)
コード例 #4
0
ファイル: tasks.py プロジェクト: pchennz/KEEN-full
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)))
コード例 #5
0
ファイル: tasks.py プロジェクト: pchennz/KEEN-full
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')
コード例 #6
0
def add_activity_notification(user_ids, aid):
    for user_id in user_ids:
        col_update(USER_, {'_id' : user_id}, {'$addToSet' : {'stack_notifs' : str(aid)}})