def get_user(uidlist):  #返回用户的背景信息
    '''
        返回用户的景信息
        输入数据:uid列表
        输出数据:users列表
    '''
    user_list = dict()
    search_result = es_user_profile.mget(index=profile_index_name,
                                         doc_type=profile_index_type,
                                         body={"ids": uidlist})["docs"]
    for item in search_result:
        uid = item['_id']
        if not item['found']:
            user_list[str(uid)] = 'other'
        else:
            data = item['_source']
            row = dict()
            for k, v in data.items():
                if k in set(zh_text):
                    row[k] = v.encode('utf-8')
                else:
                    row[k] = v
            user_list[str(uid)] = row

    return user_list
Exemplo n.º 2
0
def get_user(uidlist):  # 返回用户的背景信息
    """
        返回用户的景信息
        输入数据:uid列表
        输出数据:users列表
    """
    user_list = dict()
    search_result = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={"ids": uidlist})[
        "docs"
    ]
    for item in search_result:
        uid = item["_id"]
        if not item["found"]:
            user_list[str(uid)] = "other"
        else:
            data = item["_source"]
            row = dict()
            for k, v in data.items():
                if k in set(zh_text):
                    row[k] = v.encode("utf-8")
                else:
                    row[k] = v
            user_list[str(uid)] = row

    return user_list
Exemplo n.º 3
0
def search_attention(uid):
    stat_results = dict()
    results = dict()
    for db_num in R_DICT:
        r = R_DICT[db_num]
        ruid_results = r.hgetall('retweet_'+str(uid))
        if ruid_results:
            for ruid in ruid_results:
                if ruid != uid:
                    try:
                        stat_results[ruid] += ruid_results[ruid]
                    except:
                        stat_results[ruid] = ruid_results[ruid]
    # print 'results:', stat_results
    if not stat_results:
        return [None, 0]
    try:
        sort_state_results = sorted(stat_results.items(), key=lambda x:x[1], reverse=True)[:20]
    except:
        return [None, 0]
    #print 'sort_state_results:', sort_state_results
    uid_list = [item[0] for item in sort_state_results]
    es_profile_results = es_user_profile.mget(index='weibo_user', doc_type='user', body={'ids':uid_list})['docs']
    es_portrait_results = es_user_portrait.mget(index='user_portrait', doc_type='user', body={'ids':uid_list})['docs']
    result_list = dict()
    for i in range(len(es_profile_results)):
        item = es_profile_results[i]
        uid = item['_id']
        try:
            source = item['_source']
            uname = source['nick_name']
        except:
            uname = u'未知'
        # identify uid is in the user_portrait
        portrait_item = es_portrait_results[i]
        try:
            source = portrait_item[i]
            in_status = 1
        except:
            in_status = 0

        result_list[uid] = [uid,[uname, stat_results[uid], in_status]]
       
    return [result_list, len(stat_results)]
Exemplo n.º 4
0
def search_attention(uid):
    stat_results = dict()
    results = dict()
    for db_num in R_DICT:
        r = R_DICT[db_num]
        ruid_results = r.hgetall("retweet_" + str(uid))
        if ruid_results:
            for ruid in ruid_results:
                if ruid != uid:
                    try:
                        stat_results[ruid] += ruid_results[ruid]
                    except:
                        stat_results[ruid] = ruid_results[ruid]
    # print 'results:', stat_results
    if not stat_results:
        return [None, 0]
    try:
        sort_state_results = sorted(stat_results.items(), key=lambda x: x[1], reverse=True)[:20]
    except:
        return [None, 0]
    # print 'sort_state_results:', sort_state_results
    uid_list = [item[0] for item in sort_state_results]
    es_profile_results = es_user_profile.mget(index="weibo_user", doc_type="user", body={"ids": uid_list})["docs"]
    es_portrait_results = es_user_portrait.mget(index="user_portrait", doc_type="user", body={"ids": uid_list})["docs"]
    result_list = dict()
    for i in range(len(es_profile_results)):
        item = es_profile_results[i]
        uid = item["_id"]
        try:
            source = item["_source"]
            uname = source["nick_name"]
        except:
            uname = u"未知"
        # identify uid is in the user_portrait
        portrait_item = es_portrait_results[i]
        try:
            source = portrait_item[i]
            in_status = 1
        except:
            in_status = 0

        result_list[uid] = [uid, [uname, stat_results[uid], in_status]]

    return [result_list, len(stat_results)]
def get_user(uidlist):#返回用户的背景信息
    '''
        返回用户的景信息
        输入数据:uid列表
        输出数据:users列表
    '''
    user_list = dict()
    search_result = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={"ids": uidlist})["docs"]
    for item in search_result:
        uid = item['_id']
        if not item['found']:
            user_list[str(uid)] = 'other'
        else:
            data = item['_source']
            row = dict()
            for k,v in data.items():
                if k in set(zh_text):
                    row[k] = v.encode('utf-8')
                else:
                    row[k] = v
            user_list[str(uid)] = row

    return user_list