예제 #1
0
def judge_tw_follow_type(xnr_user_no,uid):
    exist_item = es_xnr.exists(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,\
                id=xnr_user_no)
    if not exist_item:
        tw_type = 'stranger'
    else:
        es_get = es_xnr.get(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,\
                id=xnr_user_no)['_source']
        fans_list = ''
        if es_get.has_key('fans_list'):
            fans_list = es_get['fans_list']
        followers_list = ''
        if es_get.has_key('followers_list'):
            followers_list = es_get['followers_list']

        if uid in fans_list:
            if uid in followers_list:
                tw_type = 'friends'
            else:
                tw_type = 'followed'
        elif uid in followers_list:
            tw_type = 'follow'
        else:
            tw_type = 'stranger'
    return tw_type
예제 #2
0
파일: utils.py 프로젝트: feifanhanmc/xnr2
def judge_follow_type(xnr_user_no, uid):

    exist_item = es_xnr.exists(index=weibo_xnr_fans_followers_index_name,doc_type=weibo_xnr_fans_followers_index_type,\
                id=xnr_user_no)

    if not exist_item:
        weibo_type = 'stranger'
    else:
        es_get = es_xnr.get(index=weibo_xnr_fans_followers_index_name,doc_type=weibo_xnr_fans_followers_index_type,\
                id=xnr_user_no)['_source']
        try:
            fans_list = es_get['fans_list']
        except:
            fans_list = []
        try:
            followers_list = es_get['followers_list']
        except:
            followers_list = []

        if uid in fans_list:
            if uid in followers_list:
                weibo_type = 'friends'
            else:
                weibo_type = 'followed'
        elif uid in followers_list:
            weibo_type = 'follow'
        else:
            weibo_type = 'stranger'

    return weibo_type
예제 #3
0
def save_data2es(data):
    update_uid_list = []
    create_uid_list = []
    try:
        for uid, d in data.items():
            if es.exists(index=fb_portrait_index_name, doc_type=fb_portrait_index_type, id=uid):
                update_uid_list.append(uid)
            else:
                create_uid_list.append(uid)
        #bulk create
        bulk_create_action = []
        if create_uid_list:
            for uid in create_uid_list:
                create_action = {'index':{'_id': uid}}
                bulk_create_action.extend([create_action, data[uid]])
            result = es.bulk(bulk_create_action, index=fb_portrait_index_name, doc_type=fb_portrait_index_type)
            if result['errors'] :
                print result
                return False
        #bulk update
        if update_uid_list:
            bulk_update_action = []
            for uid in update_uid_list:
                update_action = {'update':{'_id': uid}}
                bulk_update_action.extend([update_action, {'doc': data[uid]}])
            result = es.bulk(bulk_update_action, index=fb_portrait_index_name, doc_type=fb_portrait_index_type)
            if result['errors'] :
                print result
                return False
    except Exception,e:
        print e
        return False
예제 #4
0
def save(index_name, doc_type, id, data):
    if es.exists(inde=index_name, doc_type=doc_type, id=id):
        es.update(inde=index_name,
                  doc_type=doc_type,
                  id=id,
                  body={'doc': data})
    else:
        es.index(inde=index_name, doc_type=doc_type, id=id, body=data)
예제 #5
0
파일: utils.py 프로젝트: zhhhzhang/xnr1
def judge_tw_sensing_sensor(xnr_user_no, uid):
    try:
        exist_item = es_xnr.exists(index=tw_index_sensing,
                                   doc_type=tw_type_sensing,
                                   id=xnr_user_no)
    except Exception, e:
        print e
        return False
예제 #6
0
def judge_sensing_sensor(xnr_user_no,uid):
    
    exist_item = es_xnr.exists(index=index_sensing,doc_type=type_sensing,id=xnr_user_no)

    if not exist_item:
        return False 
    else:
        get_result = es_xnr.get(index=index_sensing,doc_type=type_sensing,id=xnr_user_no)['_source']
        
        social_sensors = get_result['social_sensors']
    
        if uid in social_sensors:
            return True
        else:
            return False
예제 #7
0
def save_tw_app_api_info(xnr_user_no, info):
    try:
        if es_xnr.exists(index=tw_xnr_index_name,
                         doc_type=tw_xnr_index_type,
                         id=xnr_user_no):
            print es_xnr.update(index=tw_xnr_index_name,
                                doc_type=tw_xnr_index_type,
                                body={'doc': info},
                                id=xnr_user_no)
        else:
            print es_xnr.index(index=tw_xnr_index_name,
                               doc_type=tw_xnr_index_type,
                               id=xnr_user_no,
                               body=info)
        return True
    except Exception, e:
        print e
        return False
예제 #8
0
def judge_trace_follow(xnr_user_no, uid):
    exist_item = es_xnr.exists(index=weibo_xnr_fans_followers_index_name,
                               doc_type=weibo_xnr_fans_followers_index_type,
                               id=xnr_user_no)
    if not exist_item:
        return False
    else:
        get_result = es_xnr.get(index=weibo_xnr_fans_followers_index_name,
                                doc_type=weibo_xnr_fans_followers_index_type,
                                id=xnr_user_no)['_source']
        try:
            trace_follow_list = get_result['trace_follow_list']
        except:
            trace_follow_list = []
        if uid in trace_follow_list:
            return True
        else:
            return False
예제 #9
0
def update_weibo_xnr_relations(root_uid,
                               uid,
                               data,
                               update_portrait_info=False):
    # pingtaiguanzhu 决定了是否要在平台上真正关注该用户,涉及到更改该关系时,一定要指定该字段(1或0)。
    '''
    :param root_uid: xnr_uid
    :param uid: user_uid
    :param data: relation data. eg: data={'gensuiguanzhu': 1, 'pingtaiguanzhu': 1}
    :param update_portrait_info: update or not
    :return: update success or not
    '''
    xnr_user_no = uid2xnr_user_no(root_uid)
    if xnr_user_no:
        data['platform'] = 'weibo'
        data['xnr_no'] = xnr_user_no
        data['xnr_uid'] = root_uid
        data['uid'] = uid

        # kn 调用爬虫 平台关注 2019年6月06日
        pingtaiguanzhu = data.get('pingtaiguanzhu', -1)
        pingtaiguanzhu_state = load_pingtaiguanzhu_state(root_uid, uid)
        account, password = load_user_passwd(root_uid)
        print(account, password)
        sina_operate_api = SinaOperateAPI(account, password)
        if pingtaiguanzhu != pingtaiguanzhu_state:
            if pingtaiguanzhu == 1:
                print 'go to follow--------------------------------------'
                print sina_operate_api.followed(uid=uid)
                #'gaunzhu'
                data['pingtaiguanzhu'] = 1
            elif pingtaiguanzhu == 0:
                #'quxiao'
                data['pingtaiguanzhu'] = 0

        try:
            print "one-------------"
            _id = '%s_%s' % (root_uid, uid)
            user_exist = es_xnr.exists(index=weibo_xnr_relations_index_name,
                                       doc_type=weibo_xnr_relations_index_type,
                                       id=_id)
            if user_exist:
                print "two-------------"
                if update_portrait_info:
                    protrait_info = update_weibo_user_portrait_info(uid)
                    data.update(protrait_info)
                es_result = es_xnr.update(
                    index=weibo_xnr_relations_index_name,
                    doc_type=weibo_xnr_relations_index_type,
                    id=_id,
                    body={'doc': data})
            else:
                print "three-------------"
                protrait_info = update_weibo_user_portrait_info(uid)
                data.update(protrait_info)
                es_result = es_xnr.index(
                    index=weibo_xnr_relations_index_name,
                    doc_type=weibo_xnr_relations_index_type,
                    id=_id,
                    body=data)
            print data, es_result
            return True
        except Exception, e:
            print 'update_weibo_xnr_relations Error: ', str(e)