def get_save_step_one(task_detail): es_results = es.search(index=fb_xnr_index_name,doc_type=fb_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_no2fb_id(user_no_current) #五位数 WXNR0001 print 'task_id' print task_id 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 # 第一步完成 print es.index(index=fb_xnr_index_name, doc_type=fb_xnr_index_type, id=task_id, body=item_exist) mark = True except: mark = False return mark
def get_save_step_two(task_detail): #update user_no_max = get_fb_xnr_no() user_no_current = user_no_max + 1 r.set(fb_xnr_max_no, user_no_current) task_detail['user_no'] = user_no_current task_id = user_no2fb_id(user_no_current) #五位数 FXNR0001 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()) print es.index(index=fb_xnr_index_name, doc_type=fb_xnr_index_type, id=task_id, body=item_exist) mark = True return mark, task_id