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

修改标签

parent 34d5c14b
...@@ -187,43 +187,51 @@ class TagService(ServiceBase): ...@@ -187,43 +187,51 @@ class TagService(ServiceBase):
result = cls.call_rpc('api/tag/tag/query', name=name, count=count) result = cls.call_rpc('api/tag/tag/query', name=name, count=count)
return result return result
def get_sub_tag_by_name(cls, name): def get_tag_by_name(cls, name):
try: try:
all_tags = [] all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT) client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT)
res = client.findByTagName(word=name) res = client.findByName(word=name)
res_dict = json_format.MessageToDict(res) res_dict = json_format.MessageToDict(res)
if res: if res_dict:
stringValue = res.get("Entry", {}).get("content", {}) for item in res_dict.get("Entry", []):
tag_id = stringValue.get("tag_id") is_online = item.get("content", {}).get("is_online").get("intValue")
tag_name = stringValue.get("tag_name") tag_id = item.get("content", {}).get("id").get("intValue")
tag_type = stringValue.get("tag_type") tag_name = item.get("content", {}).get("name").get("stringValue")
is_online = stringValue.get("is_online") recommend_type = item.get("content", {}).get("recommend_type").get("stringValue")
recommend_type = stringValue.get("recommend_type") tag_type = item.get("content", {}).get("tag_type").get("stringValue")
all_tags.append({"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online, if is_online == True:
"recommend_type": 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})
else:
pass
return all_tags
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
def get_sub_tag_by_id(cls, tag_id): def get_tag_by_id(cls, tag_id):
try: try:
all_tags = [] all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT) 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) res_dict = json_format.MessageToDict(res)
if res_dict: if res_dict:
stringValue = res_dict.get("Entry", {}) for item in res_dict.get("Entry", []):
for item in stringValue: is_online = item.get("content", {}).get("is_online").get("intValue")
data = item.get("content", {}).get("data", {}).get("stringValue", {}) tag_id = item.get("content", {}).get("id").get("intValue")
tag_id = data.get("tag_id") tag_name = item.get("content", {}).get("name").get("stringValue")
tag_name = data.get("tag_name") recommend_type = item.get("content", {}).get("recommend_type").get("stringValue")
tag_type = data.get("tag_type") tag_type = item.get("content", {}).get("tag_type").get("stringValue")
is_online = data.get("is_online") if is_online == True:
recommend_type = data.get("recommend_type") all_tags.append(
all_tags.append( {"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
{"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online, "recommend_type": recommend_type})
"recommend_type": recommend_type}) else:
pass
return all_tags
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
...@@ -233,17 +241,15 @@ class TagService(ServiceBase): ...@@ -233,17 +241,15 @@ class TagService(ServiceBase):
# 测试环境 # 测试环境
all_tags = [] all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT) 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) res_dict = json_format.MessageToDict(res)
if res_dict: if res_dict:
for item in res_dict.get("Entry", []): for item in res_dict.get("Entry", []):
stringValue = item.get("content", {}).get("data", {}).get("stringValue", {}) is_online = item.get("content", {}).get("is_online").get("intValue")
print(stringValue) tag_id = item.get("content", {}).get("id").get("intValue")
tag_id = stringValue.get("tag_id") tag_name = item.get("content", {}).get("name").get("stringValue")
tag_name = stringValue.get("tag_name") recommend_type = item.get("content", {}).get("recommend_type").get("stringValue")
tag_type = stringValue.get("tag_type") tag_type = item.get("content", {}).get("tag_type").get("stringValue")
is_online = stringValue.get("is_online")
recommend_type = stringValue.get("recommend_type")
if is_online == True: if is_online == True:
all_tags.append( all_tags.append(
{"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online, {"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
...@@ -255,20 +261,19 @@ class TagService(ServiceBase): ...@@ -255,20 +261,19 @@ class TagService(ServiceBase):
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
def get_sub_tag_by_names(cls, names): def get_tag_by_names(cls, names):
try: try:
all_tags = [] all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT) 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) res_dict = json_format.MessageToDict(res_dict)
if res_dict: if res_dict:
for item in res_dict.get("Entry", []): for item in res_dict.get("Entry", []):
stringValue = item.get("Entry", {}).get("content", {}).get("data", {}).get("stringValue", {}) is_online = item.get("content", {}).get("is_online").get("intValue")
tag_id = stringValue.get("tag_id") tag_id = item.get("content", {}).get("id").get("intValue")
tag_name = stringValue.get("tag_name") tag_name = item.get("content", {}).get("name").get("stringValue")
tag_type = stringValue.get("tag_type") recommend_type = item.get("content", {}).get("recommend_type").get("stringValue")
is_online = stringValue.get("is_online") tag_type = item.get("content", {}).get("tag_type").get("stringValue")
recommend_type = stringValue.get("recommend_type")
if is_online == True: if is_online == True:
all_tags.append( all_tags.append(
{"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online, {"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