コード例 #1
0
 def set_groups(self, group_list):
     #注册监听群消息的函数, group_list是需要监听消息的群组的puid列表
     if group_list:  #['']也是True
         #判断下传过来的groups_list是否有误
         try:
             groups_nickname = []
             if group_list == ['']:
                 group_list = []
             else:
                 for group_puid in group_list:
                     gs = self.groups(update=True).search(puid=group_puid)
                     if not gs:
                         return 0
                     groups_nickname.append(gs[0].name)
             self.groups_list = group_list
             print 'MyBot: set_groups: self.groups_list: ', self.groups_list
             groups_data = {
                 'wx_groups_num': len(groups_nickname),
                 'wx_groups_nickname': groups_nickname,
                 'wx_groups_puid': self.groups_list
             }
             self.change_wxxnr_redis_data(
                 {'groups_list': ','.join(self.groups_list)})
             es_xnr.update(index=wx_xnr_index_name,
                           doc_type=wx_xnr_index_type,
                           id=self.wxbot_id,
                           body={'doc': groups_data})
         except Exception, e:
             print e
             return 0
コード例 #2
0
ファイル: utils.py プロジェクト: zhhhzhang/xnr1
def get_save_step_three_1(task_detail):
    task_id = task_detail['task_id']
    # query_body = {'query':{'match_all':{}},'sort':{'user_no':{'order':'desc'}}}
    # es_result = es.search(index=fb_xnr_index_name,doc_type=fb_xnr_index_type,body=query_body)['hits']['hits']
    # task_id = es_result[0]['_source']['xnr_user_no']
    item_exist = es.get(index=fb_xnr_index_name,
                        doc_type=fb_xnr_index_type,
                        id=task_id)['_source']

    item_exist['uid'] = task_detail['id']
    item_exist['nick_name'] = task_detail['nick_name']
    item_exist['fb_mail_account'] = task_detail['fb_mail_account']
    item_exist['fb_phone_account'] = task_detail['fb_phone_account']
    item_exist['password'] = task_detail['password']
    item_exist['career'] = task_detail['career']
    item_exist['description'] = task_detail['description']
    item_exist['age'] = task_detail['age']
    item_exist['location'] = task_detail['location']
    item_exist['create_status'] = 2  # 创建完成
    # 更新 fb_xnr表
    print es.update(index=fb_xnr_index_name,
                    doc_type=fb_xnr_index_type,
                    id=task_id,
                    body={'doc': item_exist})
    mark = True
    return mark
コード例 #3
0
ファイル: utils.py プロジェクト: yuanhuiru/xnr2
def change_select_corpus(corpus_id, corpus_type, theme_daily_name,
                         create_type):
    corpus_result = es.get(index=weibo_xnr_corpus_index_name,
                           doc_type=weibo_xnr_corpus_index_type,
                           id=corpus_id)['_source']
    text = corpus_result['text']
    uid = corpus_result['uid']
    mid = corpus_result['mid']
    timestamp = corpus_result['timestamp']
    retweeted = corpus_result['retweeted']
    comment = corpus_result['comment']
    like = corpus_result['like']

    corpus_type = corpus_type
    theme_daily_name = theme_daily_name
    create_type = create_type

    try:
        es.update(index=weibo_xnr_corpus_index_name,doc_type=weibo_xnr_corpus_index_type,id=corpus_id,\
            body={"doc":{'corpus_type':corpus_type,'theme_daily_name':theme_daily_name,'text':text,\
            'uid':uid,'mid':mid,'timestamp':timestamp,'retweeted':retweeted,'comment':comment,'like':like,'create_type':create_type}})
        result = True
    except:
        result = False
    return result
コード例 #4
0
def change_authority_list(role_name, description):
    try:
        es.update(index=weibo_authority_management_index_name,doc_type=weibo_authority_management_index_type,id=role_name,\
         body={'doc':{'role_name':role_name,'description':description}})
        result = True
    except:
        result = False
    return result
コード例 #5
0
def update_xnr_map_relationship(xnr_map_detail, xnr_map_id):
    try:
        es.update(index=xnr_map_index_name,
                  doc_type=xnr_map_index_type,
                  body=xnr_map_detail,
                  id=xnr_map_id)
        result = True
    except:
        result = False
    return result
コード例 #6
0
def change_user_account(change_detail):
    user_id = change_detail['user_id']
    user_name = change_detail['user_name']
    my_xnrs = change_detail['my_xnrs']
    try:
        es.update(index=weibo_account_management_index_name,doc_type=weibo_account_management_index_type,id=user_id,\
         body={'doc':{'user_id':user_id,'user_name':user_name,'my_xnrs':my_xnrs}})
        result = True
    except:
        result = False
    return result
コード例 #7
0
def homepage():
    ip = request.remote_addr
    timestamp = int(time.time())
    user_name = ''
    _id = current_user.get_id()
    cx = sqlite3.connect("/home/ubuntu8/yuanhuiru/xnr/xnr1/xnr/flask-admin.db")
    #cx = sqlite3.connect("sqlite:///flask-admin.db")
    cu=cx.cursor()
    users = cu.execute("select id,email from user") 
    for row in users:
        if row[0] == int(_id):
            user_name = row[1]
            break
    cx.close()


    current_date = ts2datetime(timestamp)
    current_time_new = datetime2ts(current_date)

    log_id = user_name +'_'+ current_date
    
    
    exist_item = es_xnr.exists(index=weibo_log_management_index_name,doc_type=weibo_log_management_index_type,\
        id=log_id)

    if exist_item:
        get_result = es_xnr.get(index=weibo_log_management_index_name,doc_type=weibo_log_management_index_type,\
        id=log_id)['_source']

        login_ip_list = get_result['login_ip']
        login_time_list = get_result['login_time']

        login_ip_list.append(ip)
        login_time_list.append(timestamp)

        es_xnr.update(index=weibo_log_management_index_name,doc_type=weibo_log_management_index_type,\
        id=log_id,body={'doc':{'login_ip':login_ip_list,'login_time':login_time_list}})
    else:
        item_dict = {}
        item_dict['user_name'] = user_name
        item_dict['login_ip'] = [ip]
        item_dict['login_time'] = [timestamp]
        item_dict['operate_date'] = current_date
        item_dict['operate_time'] = current_time_new
        item_dict['user_id'] = ''
        #item_dict['user_name'] = ''
        item_dict['operate_content'] = ''
        
        es_xnr.index(index=weibo_log_management_index_name,doc_type=weibo_log_management_index_type,\
            id=log_id,body=item_dict)

    return render_template('index/navigationMain.html')
コード例 #8
0
ファイル: utils.py プロジェクト: zhhhzhang/xnr1
def change_hidden_expression(express_id,change_info):
    origin_word=change_info[0]
    evolution_words_string=change_info[1]
    create_type=change_info[2]
    create_time=change_info[3]
    submitter=change_info[4]

    try:
        es.update(index=weibo_hidden_expression_index_name,doc_type=weibo_hidden_expression_index_type,id=express_id,\
            body={"doc":{'origin_word':origin_word,'evolution_words_string':evolution_words_string,'create_type':create_type,'create_time':create_time,'submitter':submitter}})
        result=True
    except:
        result=False
    return result
コード例 #9
0
ファイル: utils.py プロジェクト: zhhhzhang/xnr1
def change_sensitive_words(words_id,change_info):
    rank=change_info[0]
    sensitive_words=change_info[1]
    create_type=change_info[2]
    create_time=change_info[3]
    submitter=change_info[4]

    try:
        es.update(index=weibo_sensitive_words_index_name,doc_type=weibo_sensitive_words_index_type,id=words_id,\
            body={"doc":{'rank':rank,'sensitive_words':sensitive_words,'create_type':create_type,'create_time':create_time,'submitter':submitter}})
        result=True
    except:
        result=False
    return result
コード例 #10
0
def get_modify_base_info(task_detail):
    xnr_user_no = task_detail['xnr_user_no']
    item_exists = es.get(index=tw_xnr_index_name,doc_type=tw_xnr_index_type,id=xnr_user_no)['_source']
    if task_detail.has_key('active_time'):
        item_exists['active_time'] = task_detail['active_time']
    if task_detail.has_key('day_post_average'): 
        day_post_average = task_detail['day_post_average'].split('-')
        item_exists['day_post_average'] = json.dumps(day_post_average)
    if task_detail.has_key('monitor_keywords'): 
        item_exists['monitor_keywords'] = task_detail['monitor_keywords']
    try:
        es.update(index=tw_xnr_index_name,doc_type=tw_xnr_index_type,body={'doc':item_exists}, id=xnr_user_no)
        mark = True
    except Exception,e:
        print e
        mark = False
コード例 #11
0
ファイル: utils.py プロジェクト: zhhhzhang/xnr1
def get_save_step_three_1(task_detail):
    task_id = task_detail['task_id']
    #try:
    #print 'task_detail:::',task_detail
    # print 'nick_name:::',task_detail['nick_name']
    nick_name = task_detail['nick_name'].encode('utf-8')
    operate = SinaOperateAPI()
    user_info = operate.getUserShow(screen_name=nick_name)
    uid = user_info['id']
    try:
        if task_detail['weibo_mail_account']:
            uname = task_detail['weibo_mail_account']
        else:
            uname = task_detail['weibo_phone_account']
        xnr = SinaLauncher(uname, task_detail['password'])
        xnr.login()
        uid = xnr.uid
    except:
        return '账户名或密码输入错误,请检查后输入!!'
    #uid = getUserShow(screen_name=nick_name)['data']['uid']
    #query_body = {'query':{'term':{'nick_name':nick_name}},'sort':{'user_no':{'order':'desc'}}}
    #query_body = {'query':{'match_all':{}},'sort':{'user_no':{'order':'desc'}}}
    # print 'query_body:::',query_body
    #es_result = es.search(index=weibo_xnr_index_name,doc_type=weibo_xnr_index_type,body=query_body)['hits']['hits']
    #task_id = es_result[0]['_source']['xnr_user_no']
    item_exist = es.get(index=weibo_xnr_index_name,
                        doc_type=weibo_xnr_index_type,
                        id=task_id)['_source']

    item_exist['uid'] = uid
    item_exist['nick_name'] = task_detail['nick_name']
    item_exist['weibo_mail_account'] = task_detail['weibo_mail_account']
    item_exist['weibo_phone_account'] = task_detail['weibo_phone_account']
    item_exist['password'] = task_detail['password']
    item_exist['create_status'] = 2  # 创建完成
    print 'item_exists...', item_exist
    # 更新 weibo_xnr表
    print es.update(index=weibo_xnr_index_name,
                    doc_type=weibo_xnr_index_type,
                    id=task_id,
                    body={'doc': item_exist})

    mark = True

    #except:
    #mark = False
    return mark
コード例 #12
0
def change_qq_xnr(xnr_user_no, group_names_string, mark_names_string,
                  group_numbers_string):

    get_result = es_xnr.get(index=qq_xnr_index_name,
                            doc_type=qq_xnr_index_type,
                            id=xnr_user_no)['_source']

    group_info = json.loads(get_result['group_info'])

    group_names = group_names_string.encode('utf-8').split(',')
    mark_names = mark_names_string.encode('utf-8').split(',')
    group_numbers = group_numbers_string.encode('utf-8').split(',')

    if len(group_numbers) != len(group_names) and len(group_numbers) != 0:
        return 'not_equal'

    group_numbers_origin = group_info.keys()

    delete_list = list(
        set(group_numbers_origin).difference(set(group_numbers)))
    #add_list = list(set(group_numbers).difference(set(group_numbers_origin)))

    if delete_list:
        for item in delete_list:
            group_info.pop(item)

    for i in range(len(group_numbers)):
        group_qq_number = group_numbers[i]
        group_qq_name = group_names[i]

        if group_qq_number not in group_numbers_origin:  # 新添加的
            group_info[group_qq_number] = [group_qq_name, '']
            r.sadd(r_qq_group_set,
                   group_qq_number)  ## 存入redis,后面接收群消息时,用于过滤消息。

    qq_group_num = len(group_info)
    group_info = json.dumps(group_info)

    try:
        es_xnr.update(index=qq_xnr_index_name, doc_type=qq_xnr_index_type, id=xnr_user_no,  \
            body={"doc":{'group_info':group_info,'qq_group_num':qq_group_num}})
        result = True  #'Successfully changed'
    except:
        result = False  #'Changing Failed'

    return result
コード例 #13
0
ファイル: utils.py プロジェクト: yuanhuiru/xnr1
def upadate_community(community_id):
    warning_type_list = ["敏感度剧增预警", "影响力剧增预警", "社区聚集预警"]
    weibo_community_index_name = 'weibo_trace_community_wxnr0004'
    mark = es_xnr.update(index=weibo_community_index_name,doc_type="trace_warning",id=community_id,body={'doc':{'warning_rank':3,\
            'density':0.0068,\
            'warning_type':warning_type_list
            }})
    return mark
コード例 #14
0
ファイル: utils.py プロジェクト: zhhhzhang/xnr1
def change_date_remind(task_id,date_name,keywords,create_type,create_time):
    date_result=es.get(index=weibo_date_remind_index_name,doc_type=weibo_date_remind_index_type,id=task_id)['_source']
    content_recommend=date_result['content_recommend']
    date_time=date_result['date_time']
    submitter=date_result['submitter']
    #create_type=create_type
    #keywords=keywords
    #create_time=create_time

    try:
        es.update(index=weibo_date_remind_index_name,doc_type=weibo_date_remind_index_type,id=task_id,\
            body={"doc":{'date_name':date_name,'date_time':date_time,'keywords':keywords,'create_type':create_type,\
            'create_time':create_time,'content_recommend':content_recommend,'submitter':submitter}})
        result=True
    except:
        result=False
    return result
コード例 #15
0
def get_save_step_three_1(task_detail):
    print 'hhhhhh'
    print 'task_detail...', task_detail
    task_id = task_detail['task_id']
    uid = task_detail['user_id']
    print uid
    print 'task_id...', task_id
    #nick_name = task_detail['nick_name'].encode('utf-8')
    #operate = SinaOperateAPI()
    #user_info = operate.getUserShow(screen_name=nick_name)
    #uid = user_info['id']
    #try:
    #if task_detail['weibo_mail_account']:
    #uname = task_detail['weibo_mail_account']
    #else:
    #uname = task_detail['weibo_phone_account']
    #xnr = SinaLauncher(uname, task_detail['password'])
    #status = xnr.login()
    #if not status:
    #return 'account_pwd error'
    #uid = xnr.uid
    #except:
    #return 'account_pwd error'
    #uid = getUserShow(screen_name=nick_name)['data']['uid']
    print 'task_id2...', task_id
    item_exist = es.get(index=weibo_xnr_index_name,
                        doc_type=weibo_xnr_index_type,
                        id=task_id)['_source']
    item_exist['uid'] = uid
    item_exist['nick_name'] = task_detail['nick_name']
    item_exist['weibo_mail_account'] = task_detail['weibo_mail_account']
    item_exist['weibo_phone_account'] = task_detail['weibo_phone_account']
    item_exist['password'] = task_detail['password']
    item_exist['create_status'] = 2  # 创建完成

    # 更新 weibo_xnr表
    print es.update(index=weibo_xnr_index_name,
                    doc_type=weibo_xnr_index_type,
                    id=task_id,
                    body={'doc': item_exist})

    mark = True

    #except:
    #mark = False
    return mark
コード例 #16
0
def get_save_step_three_1(task_detail):
    task_id = task_detail['task_id']
    item_exist = es.get(index=tw_xnr_index_name,doc_type=tw_xnr_index_type,id=task_id)['_source']
    
    item_exist['uid'] = task_detail['uid']
    item_exist['nick_name'] = task_detail['nick_name']
    item_exist['tw_mail_account'] = task_detail['tw_mail_account']
    item_exist['tw_phone_account'] = task_detail['tw_phone_account']
    item_exist['password'] = task_detail['password']
    item_exist['description'] = task_detail['description']
    item_exist['age'] = task_detail['age']
    item_exist['location'] = task_detail['location']
    item_exist['create_status'] = 2 # 创建完成
    # 更新 tw_xnr表
    print es.update(index=tw_xnr_index_name,doc_type=tw_xnr_index_type,id=task_id,body={'doc':item_exist})        
    mark =True
    return mark
コード例 #17
0
ファイル: utils.py プロジェクト: lvleilei/xnr1
def get_modify_base_info(task_detail):

    xnr_user_no = task_detail['xnr_user_no']

    item_exists = es.get(index=weibo_xnr_index_name,doc_type=weibo_xnr_index_type,xnr_user_no=xnr_user_no)['_source']

    item_exists['active_time'] = task_detail['active_time']
    item_exists['day_post_average'] = task_detail['day_post_average']
    item_exists['daily_interests'] = task_detail['daily_interests']
    item_exists['monitor_keywords'] = task_detail['monitor_keywords']
    try:
        es.update(index=weibo_xnr_index_name,doc_type=weibo_xnr_index_type,body={'doc':item_exist})
        mark = True
    except:
        mark = False
        
    return mark
コード例 #18
0
ファイル: utils.py プロジェクト: yuanhuiru/xnr1
def upadate_opnions_corpus(task_id):
    index_name = 'opinion_corpus'
    mark = es_xnr.update(index=index_name,
                         doc_type="text",
                         id=task_id,
                         body={'doc': {
                             'status': 0
                         }})
    return mark
コード例 #19
0
def delete_user_xnraccount(account_id, xnr_accountid):
    user_account_info = es.get(index=weibo_account_management_index_name,
                               doc_type=weibo_account_management_index_type,
                               id=account_id)
    origin_xnr_account = user_account_info['_source']['my_xnrs']

    if origin_xnr_account:
        origin_xnr_account.remove(xnr_accountid)
    else:
        origin_xnr_account = xnr_accountid

    try:
        es.update(index=weibo_account_management_index_name,doc_type=weibo_account_management_index_type,id=account_id,\
         body={'doc':{'my_xnrs':origin_xnr_account}})
        result = True
    except:
        result = False
    return result
コード例 #20
0
def delete_qq_group(xnr_user_no,group_numbers_string):

    group_numbers = group_numbers_string.encode('utf-8').split(',')

    if not group_numbers:

        return [False,'请先选择要删除的群']


    query_body_qq_exist = {
        'query':{
            'term':{'xnr_user_no':xnr_user_no}
        }
    }

    search_result = es_xnr.search(index=qq_xnr_index_name,doc_type=qq_xnr_index_type,\
        body=query_body_qq_exist)['hits']['hits']

    if search_result:
        group_info = json.loads(search_result[0]['_source']['group_info'])
        qq_number = search_result[0]['_source']['qq_number']
        r_qq_group_set = r_qq_group_set_pre + qq_number

        for item in group_numbers:
            try:
                group_qq_mark = group_info[item]['mark_name']
                print 'group_qq_mark...',group_qq_mark
                r.srem(r_qq_group_set,group_qq_mark)

                group_info.pop(item)

            except:
                pass

        qq_group_num = len(group_info)
        group_info = json.dumps(group_info)

        es_xnr.update(index=qq_xnr_index_name, doc_type=qq_xnr_index_type, id=xnr_user_no,  \
            body={"doc":{'group_info':group_info,'qq_group_num':qq_group_num}})

        return [True,'']
    else:
        return [False,'当前qq尚未添加到系统']
コード例 #21
0
def get_save_step_three_1(task_detail):
    print 'hhhhhh'
    print 'task_detail...', task_detail
    task_id = task_detail['task_id']
    print 'task_id...', task_id
    nick_name = task_detail['nick_name'].encode('utf-8')
    operate = SinaOperateAPI()
    user_info = operate.getUserShow(screen_name=nick_name)
    uid = user_info['id']
    try:
        if task_detail['weibo_mail_account']:
            uname = task_detail['weibo_mail_account']
        else:
            uname = task_detail['weibo_phone_account']
        xnr = SinaLauncher(uname, task_detail['password'])
        xnr.login()
        uid = xnr.uid
    except:
        return '账户名或密码输入错误,请检查后输入!!'
    #uid = getUserShow(screen_name=nick_name)['data']['uid']
    print 'task_id2...', task_id
    item_exist = es.get(index=weibo_xnr_index_name,
                        doc_type=weibo_xnr_index_type,
                        id=task_id)['_source']
    item_exist['uid'] = uid
    item_exist['nick_name'] = task_detail['nick_name']
    item_exist['weibo_mail_account'] = task_detail['weibo_mail_account']
    item_exist['weibo_phone_account'] = task_detail['weibo_phone_account']
    item_exist['password'] = task_detail['password']
    item_exist['create_status'] = 2  # 创建完成

    # 更新 weibo_xnr表
    print es.update(index=weibo_xnr_index_name,
                    doc_type=weibo_xnr_index_type,
                    id=task_id,
                    body={'doc': item_exist})

    mark = True

    #except:
    #mark = False
    return mark
コード例 #22
0
def add_user_xnraccount(account_id, xnr_accountid):
    user_account_info = es.get(index=weibo_account_management_index_name,
                               doc_type=weibo_account_management_index_type,
                               id=account_id)
    origin_xnr_account = user_account_info['_source']['my_xnrs']
    if origin_xnr_account:
        origin_xnr_account.extend(xnr_accountid)
    else:
        origin_xnr_account = xnr_accountid
    new_xnr_account = []
    [
        new_xnr_account.append(i) for i in origin_xnr_account
        if not i in new_xnr_account
    ]
    try:
        es.update(index=weibo_account_management_index_name,doc_type=weibo_account_management_index_type,id=account_id,\
         body={'doc':{'my_xnrs':new_xnr_account}})
        result = True
    except:
        result = False
    return result
コード例 #23
0
def cron_compute_mark_wx():
    current_time = int(time.time() - DAY)
    current_date = ts2datetime(current_time)
    current_time_new = datetime2ts(current_date)
    #加载数据库中虚拟人信息
    xnr_query_body = {'query': {'match_all': {}}, 'size': MAX_VALUE}
    xnr_results = es_xnr.search(index=wx_xnr_index_name,
                                doc_type=wx_xnr_index_type,
                                body=xnr_query_body)['hits']['hits']
    flag = False
    for result in xnr_results:
        xnr_user_no = result['_source']['xnr_user_no']
        puid = result['_source']['puid']
        #计算
        influence_dict = get_influence_at_num(puid)
        penetration_dict = get_penetration_num(xnr_user_no)
        safe_dict = wx_history_count(xnr_user_no, puid, current_time_new)
        #整理
        _id = xnr_user_no + '_' + current_date
        xnr_user_detail = {
            'influence': influence_dict['mark'],
            'penetration': penetration_dict['mark'],
            'safe': safe_dict['mark'],
            'daily_be_at_num': influence_dict['daily_be_at_num'],
            'total_be_at_num': influence_dict['total_be_at_num'],
            'daily_sensitive_num': penetration_dict['sensitive_info'],
            'total_post_num': safe_dict['total_post_num'],
            'daily_post_num': safe_dict['daily_post_num'],
            'date_time': current_date,
            'timestamp': current_time_new,
            'xnr_user_no': xnr_user_no,
            'puid': puid
        }
        #并存储
        wx_xnr_history_count_mappings()  #先确保数据库存在
        try:
            if es_xnr.exists(index=wx_xnr_history_count_index_name,
                             doc_type=wx_xnr_history_count_index_type,
                             id=_id):
                msg = es_xnr.update(index=wx_xnr_history_count_index_name,
                                    doc_type=wx_xnr_history_count_index_type,
                                    body={'doc': xnr_user_detail},
                                    id=_id)
            else:
                msg = es_xnr.index(index=wx_xnr_history_count_index_name,
                                   doc_type=wx_xnr_history_count_index_type,
                                   id=_id,
                                   body=xnr_user_detail)
            flag = True
            print msg
        except Exception, e:
            print 'cron_compute_mark_wx Exception: ', str(e)
            return False
コード例 #24
0
ファイル: utils.py プロジェクト: yuanhuiru/xnr1
def update_trace_status(community_id, trace_status, now_time):
    if S_TYPE == 'test':
        now_time = datetime2ts(WEIBO_COMMUNITY_DATE)
    else:
        now_time = int(time.time())
    weibo_community_index_name = get_community_index(now_time)
    # print weibo_community_index_name
    # print 'trace_status11',trace_status
    # print 'now_time',ts2datetime(now_time)
    try:
        update_result = es_xnr.update(index=weibo_community_index_name,doc_type=weibo_community_index_type,\
            id=community_id,body={'doc':{'community_status':trace_status}})
        mark = True
    except:
        mark = False
    return mark
コード例 #25
0
def create_qq_xnr(xnr_info):
    # xnr_info = [qq_number,qq_groups,nickname,active_time,create_time]
    print '============1'
    qq_group_exist_list = ''  #[]
    qq_group_new_list = []
    qq_number = xnr_info['qq_number']
    #qq_groups = xnr_info['qq_groups'].encode('utf-8').split(',')
    group_names = xnr_info['group_names'].encode('utf-8').split(',')
    mark_names = xnr_info['mark_names'].encode('utf-8').split(',')
    group_numbers = xnr_info['group_numbers'].encode('utf-8').split(',')
    print 'group_numbers...', group_numbers
    print 'mark_names......', mark_names
    print 'group_names.....', group_names
    if not len(group_names) == len(mark_names) == len(group_numbers):
        #return [False,'群名称数量和群号码数量不一致']
        return [False, '群名称数量、群备注数量和群号码数量不一致']

    if len(group_numbers) == 0:
        return [False, '输入不能为空']

    # redis 群名
    r_qq_group_set = r_qq_group_set_pre + qq_number

    mark_name_exist_list = []

    nickname = xnr_info['nickname']
    access_id = xnr_info['access_id']
    remark = xnr_info['remark']
    submitter = xnr_info['submitter']

    #r_qq_group_mark_set = r_qq_group_mark_set_pre + qq_number

    query_body_qq_exist = {'query': {'term': {'qq_number': qq_number}}}

    search_result = es_xnr.search(index=qq_xnr_index_name,doc_type=qq_xnr_index_type,\
        body=query_body_qq_exist)['hits']['hits']
    print '456'
    if search_result:
        #return ['当前qq已经被添加!',qq_group_exist_list]
        group_info = json.loads(search_result[0]['_source']['group_info'])
        group_info_keys = group_info.keys()  # 群号

        for i in range(len(group_numbers)):

            group_qq_number = group_numbers[i]
            group_qq_name = group_names[i]
            group_qq_mark = mark_names[i]

            if group_qq_number in group_info_keys:  # 若群号已添加,则可修改群名
                #qq_group_exist_list.append(group_qq_number)
                #mark_name_list = group_info[group_qq_number]['mark_name']
                group_name_list = group_info[group_qq_number]['group_name']
                r.sadd(r_qq_group_set, group_qq_mark)

                if not group_qq_name in group_name_list:
                    group_info[group_qq_number]['group_name'].append(
                        group_qq_name)

            else:  # 若群号未添加,首先检查备注名是否重复,若重复,则返回,否则,正常流程。
                if not r.sadd(r_qq_group_set, group_qq_mark):  # 群号唯一 改为 备注唯一
                    mark_name_exist_list.append(group_qq_mark)
                else:
                    group_info[group_qq_number] = {
                        'mark_name': group_qq_mark,
                        'group_name': [group_qq_name]
                    }

        if mark_name_exist_list:
            return [False, '失败!以下备注名重复:' + ','.join(mark_name_exist_list)]

        qqbot_port = search_result[0]['_source']['qqbot_port']

        # 把不在的群添加进去
        qq_exist_result = search_result[0]['_source']
        xnr_user_no = qq_exist_result['xnr_user_no']
        qq_exist_result['group_info'] = json.dumps(group_info)

        qq_exist_result['qq_group_num'] = len(group_info)

        es_xnr.update(index=qq_xnr_index_name,doc_type=qq_xnr_index_type,id=xnr_user_no,\
            body={'doc':qq_exist_result})

        result = True

    else:

        # active_time = xnr_info[3]
        create_ts = xnr_info['create_ts']
        exist_port_list = get_all_ports()  #返回list形式int型端口号
        qqbot_port = find_port(exist_port_list)
        #qq_groups_num = len(qq_groups)
        # qq_groups = getgroup_v2(qq_number)
        user_no_current = get_qq_xnr_no()
        xnr_user_no = user_no2qq_id(user_no_current)  #五位数 QXNR0001

        # 群信息
        group_info = {}

        for i in range(len(group_numbers)):
            group_qq_number = group_numbers[i]
            group_qq_name = group_names[i]
            group_qq_mark = mark_names[i]
            print '1..', group_qq_number
            print '2..', group_qq_name
            print '3..', group_qq_mark

            if not r.sadd(
                    r_qq_group_set,
                    group_qq_mark):  # 群号唯一 改为 备注唯一. 存入redis,后面接收群消息时,用于过滤消息。
                mark_name_exist_list.append(group_qq_mark)
            else:
                group_info[group_qq_number] = {
                    'mark_name': group_qq_mark,
                    'group_name': [group_qq_name]
                }

        if mark_name_exist_list:
            return [False, '失败!以下备注名重复:' + ','.join(mark_name_exist_list)]

        qq_group_num = len(group_info)
        group_info = json.dumps(group_info)

        #try:
        ## 存入es
        print es_xnr.index(index=qq_xnr_index_name, doc_type=qq_xnr_index_type, id=xnr_user_no, \
        body={'qq_number':qq_number,'nickname':nickname,'group_info':group_info,'qq_group_num':qq_group_num,'create_ts':create_ts,\
                'qqbot_port':qqbot_port,'user_no':user_no_current,'xnr_user_no':xnr_user_no,\
                'access_id':access_id,'remark':remark,'submitter':submitter})

        result = True
        # except:
        #     result = False

    print 'before python recieveQQGroupMessage:', result

    #print 'output:', p2.stdout.readlines()

    return [result, qq_group_exist_list]