def submit_attribute(attribute_name, attribute_value, submit_user, submit_date): status = False #maybe there have to identify the user admitted to submit attribute try: attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: attribute_exist = {} #identify the tag name not same with the identify_attribute_list if attribute_exist == {} and attribute_name not in identify_attribute_list: input_data = dict() now_ts = time.time() date = ts2datetime(now_ts) input_data['attribute_name'] = attribute_name input_data['attribute_value'] = '&'.join(attribute_value.split(',')) input_data['user'] = submit_user input_data['date'] = submit_date es_tag.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name, body=input_data) status = True #put mappings to es_user_portrait es.indices.put_mapping(index=user_index_name, doc_type=user_index_type, \ body={'properties':{attribute_name:{'type':'string', 'index':'not_analyzed'}}}, ignore=400) return status
def submit_attribute(attribute_name, attribute_value, submit_user, submit_date): status = False id_attribute = '-'.join([submit_user, attribute_name]) print 'id_attribute:', id_attribute #maybe there have to identify the user admitted to submit attribute try: attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except: attribute_exist = {} #identify the tag name not same with the identify_attribute_list if attribute_exist == {} and id_attribute not in identify_attribute_list: input_data = dict() now_ts = time.time() date = ts2datetime(now_ts) input_data['attribute_name'] = attribute_name input_data['attribute_value'] = '&'.join(attribute_value.split(',')) input_data['user'] = submit_user input_data['date'] = submit_date es_tag.index(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute, body=input_data) status = True #put mappings to es_user_portrait submit_user_tag = str(submit_user) + "-tag" exist_field = es.indices.get_field_mapping(index=user_index_name, doc_type=user_index_type, field=submit_user_tag) if not exist_field: es.indices.put_mapping(index=user_index_name, doc_type=user_index_type, \ body={'properties':{submit_user_tag:{'type':'string', 'analyzer':'my_analyzer'}}}, ignore=400) return status
def add_attribute_portrait(uid, attribute_name, attribute_value, submit_user): status = False submit_user_tag = submit_user + "-tag" id_attribute = submit_user + "-" + attribute_name add_attribute_value = attribute_name + "-" + attribute_value # identify the user exist # identify the attribute exist # identify the attribute exist in user_portrait # add attribute in user_portrait try: user_result = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: return 'no user' try: attribute_result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except: return 'no attribute' attribute_value_list = attribute_result['attribute_value'].split('&') if attribute_value not in attribute_value_list: return 'no attribute value' value_set = set() for value in attribute_value_list: value_set.add(attribute_name + '-' + value) # submit_user_attribute = user_result.get(submit_user_tag, '') # 个人是否存在该管理员打上的个人标签 tmp_attribute_set = set(submit_user_attribute.split('&')) attribute_exist = tmp_attribute_set & value_set if attribute_exist: return 'attribute exist' user_result[submit_user_tag] = "&".join([submit_user_attribute, add_attribute_value]) es.index(index=user_index_name, doc_type=user_index_type, id=uid, body=user_result) status = True return status
def add_tag2group(uid_list, attribute_name, attribute_value): status = False #identify the attribute exist #for uid in uid_list #identify the attribute not in this user #add tag to this user try: attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: return 'no attribute' attribute_exist_value_list = attribute_exist['attribute_value'].split('&') if attribute_value not in attribute_exist_value_list: return 'no attribute value' for uid in uid_list: try: user_exist = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: user_exist = {} if user_exist and attribute_name not in user_exist: add_attribute_dict = {attribute_name: attribute_value} es.update(index=user_index_name, doc_type=user_index_type, id=uid, body={'doc': add_attribute_dict}) status = True return status
def change_attribute_portrait(uid, attribute_name, attribute_value, submit_user): status = False submit_user_tag = submit_user + "-tag" id_attribute = submit_user + "-" + attribute_name #identify the user exist #identify the attribute exist #identify the attribute value exist #identify the submit_user have been admitted----without try: user_result = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: return 'no user' try: attribute_result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except: return 'no attribute' value_list = attribute_result['attribute_value'].split('&') if attribute_value not in value_list: return 'no attribute value' submit_user_attribute = user_result.get(submit_user_tag, '') # 个人是否存在该管理员打上的个人标签 if attribute_name not in submit_user_attribute: return 'personal attribute no exist' tmp_attribute_list = submit_user_attribute.split("&") attribute_list = [] for item in tmp_attribute_list: if attribute_name in item: attribute_list.append(attribute_name + '-' + attribute_value) else: attribute_list.append(item) user_result[submit_user_tag] = "&".join(attribute_list) es.index(index=user_index_name, doc_type=user_index_type, id=uid, body=user_result) status = True return status
def delete_attribute(attribute_name): status = False try: result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except Exception, e: raise e return status
def submit_attribute(attribute_name, attribute_value, submit_user, submit_date): print "-----------submit_user---------" print submit_user status = False id_attribute = '-'.join([submit_user,attribute_name]) print 'id_attribute:', id_attribute #maybe there have to identify the user admitted to submit attribute try: attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except: attribute_exist = {} #identify the tag name not same with the identify_attribute_list if attribute_exist == {} and id_attribute not in identify_attribute_list: input_data = dict() now_ts = time.time() date = ts2datetime(now_ts) input_data['attribute_name'] = attribute_name input_data['attribute_value'] = '&'.join(attribute_value.split(',')) input_data['user'] = submit_user input_data['date'] = submit_date es_tag.index(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute, body=input_data) status = True #put mappings to es_user_portrait submit_user_tag = str(submit_user) + "-tag" exist_field = es.indices.get_field_mapping(index=user_index_name, doc_type=user_index_type, field=submit_user_tag) if not exist_field: es.indices.put_mapping(index=user_index_name, doc_type=user_index_type, \ body={'properties':{submit_user_tag:{'type':'string', 'analyzer':'my_analyzer'}}}, ignore=400) return status
def add_tag2group(uid_list, attribute_name, attribute_value, submit_user): id_attribute = submit_user + "-" + attribute_name add_attribute = attribute_name + "-" + attribute_value submit_user_tag = submit_user + "-tag" status = False #identify the attribute exist #for uid in uid_list #identify the attribute not in this user #add tag to this user try: attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except: return 'no attribute' attribute_exist_value_list = attribute_exist['attribute_value'].split('&') if attribute_value not in attribute_exist_value_list: return 'no attribute value' for uid in uid_list: try: user_exist = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: user_exist = {} continue submit_user_attribute = user_exist.get(submit_user_tag, '') if user_exist and attribute_name not in submit_user_attribute: user_exist[submit_user_tag] = "&".join([submit_user_attribute, add_attribute]) es.index(index=user_index_name, doc_type=user_index_type, id=uid, body=user_exist) status = True return status
def change_attribute_portrait(uid, attribute_name, attribute_value, submit_user): status = False #identify the user exist #identify the attribute exist #identify the attribute value exist #identify the submit_user have been admitted----without try: user_exist = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: return 'no user' try: attribute_result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: return 'no attribute' value_list = attribute_result['attribute_value'].split('&') if attribute_value not in value_list: return 'no attribute value' change_attribute_dict = {attribute_name: attribute_value} es.update(index=user_index_name, doc_type=user_index_type, id=uid, body={'doc': change_attribute_dict}) status = True return status
def add_attribute_portrait(uid, attribute_name, attribute_value, submit_user): status = False # identify the user exist # identify the attribute exist # identify the attribute exist in user_portrait # add attribute in user_portrait try: user_result = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: return 'no user' try: attribute_result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: return 'no attribute' attribute_value_list = attribute_result['attribute_value'].split('&') if attribute_value not in attribute_value_list: return 'no attribute value' if attribute_name in user_result: return 'attribute exist' add_attribute_dict = {attribute_name: attribute_value} es.update(index=user_index_name, doc_type=user_index_type, id=uid, body={'doc': add_attribute_dict}) status = True return status
def get_attribute_value(attribute_name): attribute_value_list = [] try: attribute_result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: return 'no attribute' attribute_value_string = attribute_result['attribute_value'] attribute_value_list = attribute_value_string.split('&') return attribute_value_list
def delete_attribute(attribute_name, submit_user): status = False id_attribute = "-".join([submit_user,attribute_name]) submit_user_tag = submit_user+"-tag" try: result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except Exception, e: #raise e return status
def delete_attribute(attribute_name, submit_user): status = False id_attribute = "-".join([submit_user, attribute_name]) submit_user_tag = submit_user + "-tag" try: result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except Exception, e: #raise e return status
def get_attribute_value(attribute_name, submit_user): id_attribute = submit_user + "-" + attribute_name print id_attribute attribute_value_list = [] #try: attribute_result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] #except: # return 'no attribute' print 'attribute_result:', attribute_result attribute_value_string = attribute_result['attribute_value'] attribute_value_list = attribute_value_string.split('&') return attribute_value_list
def change_attribute(attribute_name, value, user, state): status = False # identify the attribute_name is in ES - custom attribute try: result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: result = None return status value_list = '&'.join(value.split(',')) result['attribute_name'] = attribute_name result['attribute_value'] = value_list result['user'] = user now_ts = time.time() now_date = ts2datetime(now_ts) result['date'] = now_date es_tag.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name ,body=result) status = True return status
def add_attribute_portrait(uid, attribute_name, attribute_value, submit_user): status = False submit_user_tag = submit_user + "-tag" id_attribute = submit_user + "-" + attribute_name add_attribute_value = attribute_name + "-" + attribute_value # identify the user exist # identify the attribute exist # identify the attribute exist in user_portrait # add attribute in user_portrait try: user_result = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: return 'no user' try: attribute_result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except: return 'no attribute' attribute_value_list = attribute_result['attribute_value'].split('&') if attribute_value not in attribute_value_list: return 'no attribute value' value_set = set() for value in attribute_value_list: value_set.add(attribute_name + '-' + value) # submit_user_attribute = user_result.get(submit_user_tag, '') # 个人是否存在该管理员打上的个人标签 tmp_attribute_set = set(submit_user_attribute.split('&')) attribute_exist = tmp_attribute_set & value_set if attribute_exist: return 'attribute exist' if submit_user_attribute: user_result[submit_user_tag] = "&".join( [submit_user_attribute, add_attribute_value]) else: user_result[submit_user_tag] = add_attribute_value es.index(index=user_index_name, doc_type=user_index_type, id=uid, body=user_result) status = True return status
def add_tag2group(uid_list, attribute_name, attribute_value, submit_user): id_attribute = submit_user + "-" + attribute_name add_attribute = attribute_name + "-" + attribute_value submit_user_tag = submit_user + "-tag" status = False #identify the attribute exist #for uid in uid_list #identify the attribute not in this user #add tag to this user try: attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source'] except: return 'no attribute' attribute_exist_value_list = attribute_exist['attribute_value'].split('&') if attribute_value not in attribute_exist_value_list: return 'no attribute value' for uid in uid_list: try: user_exist = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: user_exist = {} continue submit_user_attribute = user_exist.get(submit_user_tag, '') if user_exist and attribute_name not in submit_user_attribute: if submit_user_attribute: user_exist[submit_user_tag] = "&".join( [submit_user_attribute, add_attribute]) else: user_exist[submit_user_tag] = add_attribute es.index(index=user_index_name, doc_type=user_index_type, id=uid, body=user_exist) status = True return status
def add_tag2group(uid_list, attribute_name, attribute_value): status = False #identify the attribute exist #for uid in uid_list #identify the attribute not in this user #add tag to this user try: attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: return 'no attribute' attribute_exist_value_list = attribute_exist['attribute_value'].split('&') if attribute_value not in attribute_exist_value_list: return 'no attribute value' for uid in uid_list: try: user_exist = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: user_exist = {} if user_exist and attribute_name not in user_exist: add_attribute_dict = {attribute_name: attribute_value} es.update(index=user_index_name, doc_type=user_index_type, id=uid, body={'doc':add_attribute_dict}) status = True return status
def change_attribute(attribute_name, value, user, state): status = False # identify the attribute_name is in ES - custom attribute try: result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: result = None return status value_list = '&'.join(value.split(',')) result['attribute_name'] = attribute_name result['attribute_value'] = value_list result['user'] = user now_ts = time.time() now_date = ts2datetime(now_ts) result['date'] = now_date es_tag.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name, body=result) status = True return status
def add_attribute_portrait(uid, attribute_name, attribute_value, submit_user): status = False # identify the user exist # identify the attribute exist # identify the attribute exist in user_portrait # add attribute in user_portrait try: user_result = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: return 'no user' try: attribute_result = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: return 'no attribute' attribute_value_list = attribute_result['attribute_value'].split('&') if attribute_value not in attribute_value_list: return 'no attribute value' if attribute_name in user_result: return 'attribute exist' add_attribute_dict = {attribute_name: attribute_value} es.update(index=user_index_name, doc_type=user_index_type, id=uid, body={'doc':add_attribute_dict}) status = True return status