示例#1
0
文件: utils.py 项目: lvleilei/xnr1
def get_save_step_one(task_detail):

    es_results = es.search(index=weibo_xnr_index_name,doc_type=weibo_xnr_index_type,body={'query':{'match_all':{}},\
                    'sort':{'user_no':{'order':'desc'}}})['hits']['hits']
    if es_results:
        user_no_max = es_results[0]['_source']['user_no']
        user_no_current = user_no_max + 1 
    else:
        user_no_current = 1

    task_detail['user_no'] = user_no_current
    task_id = user_no2_id(user_no_current)  #五位数 WXNR0001

    try:    
        item_exist = dict()
        item_exist['user_no'] = task_detail['user_no']
        item_exist['domain_name'] = task_detail['domain_name']
        item_exist['role_name'] = task_detail['role_name']
        item_exist['psy_feature'] = '&'.join(task_detail['psy_feature'].encode('utf-8').split(','))
        item_exist['political_side'] = task_detail['political_side']
        item_exist['business_goal'] = '&'.join(task_detail['business_goal'].encode('utf-8').split(','))
        item_exist['daily_interests'] = '&'.join(task_detail['daily_interests'].encode('utf-8').split(','))
        item_exist['monitor_keywords'] = '&'.join(task_detail['monitor_keywords'].encode('utf-8').split(','))
        item_exist['create_status'] = 0 # 第一步完成
        
        es.index(index=weibo_xnr_index_name,doc_type=weibo_xnr_index_type,id=task_id,body=item_exist)

        mark = True
    except:
        
        mark = False

    return mark
示例#2
0
文件: utils.py 项目: zhhhzhang/xnr1
def get_save_step_two(task_detail):

    task_id = task_detail['task_id']
    # es_results = es.search(index=weibo_xnr_index_name,doc_type=weibo_xnr_index_type,body={'query':{'match_all':{}},\
    #                 'sort':{'user_no':{'order':'desc'}}})['hits']['hits']
    # if es_results:
    #     user_no_max = es_results[0]['_source']['user_no']
    #     user_no_current = user_no_max + 1
    # else:
    #     user_no_current = 1
    # 如果是首次创建时,点到了第二步中,下一步,则 task_id 尚未分配,则首先分配 task_id
    # 如果是从未完成虚拟人中,点到了第二步中,下一步,则task_id已分配,则沿用原来的task_id
    if not task_id:

        user_no_current = get_wb_xnr_no()

        task_detail['user_no'] = user_no_current
        task_id = user_no2_id(user_no_current)  #五位数 WXNR0001

    item_exist = dict()
    item_exist['submitter'] = task_detail['submitter']
    item_exist['user_no'] = task_detail['user_no']
    item_exist['domain_name'] = task_detail['domain_name']
    item_exist['role_name'] = task_detail['role_name']
    item_exist['psy_feature'] = '&'.join(
        task_detail['psy_feature'].encode('utf-8').split(','))
    item_exist['political_side'] = task_detail['political_side']
    item_exist['business_goal'] = '&'.join(
        task_detail['business_goal'].encode('utf-8').split(','))
    item_exist['daily_interests'] = '&'.join(
        task_detail['daily_interests'].encode('utf-8').split(','))
    item_exist['monitor_keywords'] = ','.join(
        task_detail['monitor_keywords'].encode('utf-8').split(','))

    item_exist['active_time'] = '&'.join(task_detail['active_time'].split('-'))
    item_exist['day_post_average'] = json.dumps(
        task_detail['day_post_average'].split('-'))
    item_exist['create_status'] = 1  # 第二步完成
    item_exist['xnr_user_no'] = task_id  # 虚拟人编号
    item_exist['create_time'] = int(time.time())

    es.index(index=weibo_xnr_index_name,
             doc_type=weibo_xnr_index_type,
             id=task_id,
             body=item_exist)

    mark = True
    #except:
    #    mark = False

    return mark, task_id
示例#3
0
def get_save_step_two(task_detail):

    item_exist = dict()
    item_exist['submitter'] = task_detail['submitter']
    item_exist['domain_name'] = task_detail['domain_name']
    item_exist['role_name'] = task_detail['role_name']
    item_exist['psy_feature'] = '&'.join(
        task_detail['psy_feature'].encode('utf-8').split(','))
    item_exist['political_side'] = task_detail['political_side']
    item_exist['business_goal'] = '&'.join(
        task_detail['business_goal'].encode('utf-8').split(','))
    item_exist['daily_interests'] = '&'.join(
        task_detail['daily_interests'].encode('utf-8').split(','))
    item_exist['monitor_keywords'] = ','.join(
        task_detail['monitor_keywords'].encode('utf-8').split(','))
    #item_exist['sex'] = task_detail['sex']

    # item_exist['nick_name'] = task_detail['nick_name']
    # item_exist['age'] = task_detail['age']
    # item_exist['location'] = task_detail['location']
    # item_exist['career'] = task_detail['career']
    # item_exist['description'] = task_detail['description']
    item_exist['active_time'] = '&'.join(task_detail['active_time'].split('-'))
    item_exist['day_post_average'] = json.dumps(
        task_detail['day_post_average'].split('-'))
    item_exist['create_status'] = 1  # 第二步完成
    item_exist['create_time'] = int(time.time())

    task_source = task_detail['task_source']
    task_id = ''
    if task_source == 'new':

        user_no_current = get_wb_xnr_no()
        item_exist['user_no'] = user_no_current  #task_detail['user_no']
        task_id = user_no2_id(user_no_current)  #五位数 WXNR0001
        item_exist['xnr_user_no'] = task_id  # 虚拟人编号
        es.index(index=weibo_xnr_index_name,
                 doc_type=weibo_xnr_index_type,
                 id=task_id,
                 body=item_exist)

    mark = True
    #except:
    #    mark = False

    return mark, task_id