Commit 8496709e authored by 李小芳's avatar 李小芳

修改标签

parent 34d5c14b
......@@ -187,43 +187,51 @@ class TagService(ServiceBase):
result = cls.call_rpc('api/tag/tag/query', name=name, count=count)
return result
def get_sub_tag_by_name(cls, name):
def get_tag_by_name(cls, name):
try:
all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT)
res = client.findByTagName(word=name)
res = client.findByName(word=name)
res_dict = json_format.MessageToDict(res)
if res:
stringValue = res.get("Entry", {}).get("content", {})
tag_id = stringValue.get("tag_id")
tag_name = stringValue.get("tag_name")
tag_type = stringValue.get("tag_type")
is_online = stringValue.get("is_online")
recommend_type = stringValue.get("recommend_type")
all_tags.append({"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
"recommend_type": recommend_type})
if res_dict:
for item in res_dict.get("Entry", []):
is_online = item.get("content", {}).get("is_online").get("intValue")
tag_id = item.get("content", {}).get("id").get("intValue")
tag_name = item.get("content", {}).get("name").get("stringValue")
recommend_type = item.get("content", {}).get("recommend_type").get("stringValue")
tag_type = item.get("content", {}).get("tag_type").get("stringValue")
if is_online == True:
all_tags.append(
{"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
"recommend_type": recommend_type})
else:
pass
return all_tags
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_sub_tag_by_id(cls, tag_id):
def get_tag_by_id(cls, tag_id):
try:
all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT)
res = res = client.findByTagId(tagId=tag_id)
res = res = client.findById(tagId=tag_id)
res_dict = json_format.MessageToDict(res)
if res_dict:
stringValue = res_dict.get("Entry", {})
for item in stringValue:
data = item.get("content", {}).get("data", {}).get("stringValue", {})
tag_id = data.get("tag_id")
tag_name = data.get("tag_name")
tag_type = data.get("tag_type")
is_online = data.get("is_online")
recommend_type = data.get("recommend_type")
all_tags.append(
{"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
"recommend_type": recommend_type})
for item in res_dict.get("Entry", []):
is_online = item.get("content", {}).get("is_online").get("intValue")
tag_id = item.get("content", {}).get("id").get("intValue")
tag_name = item.get("content", {}).get("name").get("stringValue")
recommend_type = item.get("content", {}).get("recommend_type").get("stringValue")
tag_type = item.get("content", {}).get("tag_type").get("stringValue")
if is_online == True:
all_tags.append(
{"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
"recommend_type": recommend_type})
else:
pass
return all_tags
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
......@@ -233,17 +241,15 @@ class TagService(ServiceBase):
# 测试环境
all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT)
res = client.findByTagIds(tagIds=tag_ids)
res = client.findByIds(tagIds=tag_ids)
res_dict = json_format.MessageToDict(res)
if res_dict:
for item in res_dict.get("Entry", []):
stringValue = item.get("content", {}).get("data", {}).get("stringValue", {})
print(stringValue)
tag_id = stringValue.get("tag_id")
tag_name = stringValue.get("tag_name")
tag_type = stringValue.get("tag_type")
is_online = stringValue.get("is_online")
recommend_type = stringValue.get("recommend_type")
is_online = item.get("content", {}).get("is_online").get("intValue")
tag_id = item.get("content", {}).get("id").get("intValue")
tag_name = item.get("content", {}).get("name").get("stringValue")
recommend_type = item.get("content", {}).get("recommend_type").get("stringValue")
tag_type = item.get("content", {}).get("tag_type").get("stringValue")
if is_online == True:
all_tags.append(
{"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
......@@ -255,20 +261,19 @@ class TagService(ServiceBase):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_sub_tag_by_names(cls, names):
def get_tag_by_names(cls, names):
try:
all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT)
res_dict = client.findByTagNames(words=names)
res_dict = client.findByNameList(words=names)
res_dict = json_format.MessageToDict(res_dict)
if res_dict:
for item in res_dict.get("Entry", []):
stringValue = item.get("Entry", {}).get("content", {}).get("data", {}).get("stringValue", {})
tag_id = stringValue.get("tag_id")
tag_name = stringValue.get("tag_name")
tag_type = stringValue.get("tag_type")
is_online = stringValue.get("is_online")
recommend_type = stringValue.get("recommend_type")
is_online = item.get("content", {}).get("is_online").get("intValue")
tag_id = item.get("content", {}).get("id").get("intValue")
tag_name = item.get("content", {}).get("name").get("stringValue")
recommend_type = item.get("content", {}).get("recommend_type").get("stringValue")
tag_type = item.get("content", {}).get("tag_type").get("stringValue")
if is_online == True:
all_tags.append(
{"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment