Commit f47dfb70 authored by haowang's avatar haowang

fix code

parent 4da8995e
...@@ -85,38 +85,33 @@ class CreatePictorial(BaseView): ...@@ -85,38 +85,33 @@ class CreatePictorial(BaseView):
) )
return ret return ret
def revise_comments(self, comments, from_id): def revise_comments(self, comment, from_id):
ret = [] ret = []
for obj in comments: comment['from_id'] = from_id
obj['from_id'] = from_id comment['content'] = comment.get('comment')
obj['content'] = obj.get('comment') reply = comment.pop('reply', None)
reply = obj.pop('reply', None) if not reply:
if not reply: return comment, ret
continue for info in reply:
for info in reply: info['from_id'] = comment.get('from_id')
info['from_id'] = obj.get('from_id') info['reply_id'] = comment.get('id')
info['reply_id'] = obj.get('id') info['type'] = comment.get('type')
info['type'] = obj.get('type')
ret.append(info)
ret.append(info) return comment, ret
return obj, ret
def create_comment(self, comment_list, from_id, platform, topic_id=None, pictorial_id=None): def create_comment(self, comment_list, from_id, platform, topic_id=None, pictorial_id=None):
top_comment, comments = self.revise_comments(comment_list, from_id) top_comment, comments = self.revise_comments(comment_list, from_id)
top_comment['user_id'] = self.get_user_id(id_=top_comment.get('user').get('id'), platform=platform) top_comment['user_id'] = self.get_user_id(id_=top_comment.get('user').get('id'), platform=platform)
top_comment.pop('user') top_comment.pop('user')
error, ret = self.call_rpc('venus/community/crawl/replys', data=[top_comment], platform=platform, topic_id=topic_id, pictorial_id=pictorial_id) error, ret = self.call_rpc('venus/community/crawl/replys', data=[top_comment], platform=platform, topic_id=topic_id, pictorial_id=pictorial_id)
if error: if error:
return error, ret return error, ret
top_id = ret.get('reply_ids')[0] top_id = ret.get('reply_ids')[0]
top_id = 0
for obj in comments: for obj in comments:
obj['user_id'] = self.get_user_id(id_=obj.get('user').get('id'), platform=platform) obj['user_id'] = self.get_user_id(id_=obj.get('user').get('id'), platform=platform)
obj.pop('user') obj.pop('user')
error, _ = self.call_rpc('venus/community/crawl/replys', data=comments, platform=platform, topic_id=topic_id, pictorial_id=pictorial_id, top_id=top_id) error, _ = self.call_rpc('venus/community/crawl/replys', data=comments, platform=platform, topic_id=topic_id, pictorial_id=pictorial_id, top_id=top_id)
if error: if error:
return error, None return error, None
...@@ -135,7 +130,8 @@ class CreatePictorial(BaseView): ...@@ -135,7 +130,8 @@ class CreatePictorial(BaseView):
continue continue
from_id = topic.get('id') from_id = topic.get('id')
if platform == GRAP_PLATFORM.XIAOHONGSHU: if platform == GRAP_PLATFORM.XIAOHONGSHU:
error, _ = self.create_comment(comment_list=topic_comments, from_id=from_id, platform=platform, topic_id=topic_obj.get('id')) for topic_comment in topic_comments:
error, _ = self.create_comment(comment_list=topic_comment, from_id=from_id, platform=platform, topic_id=topic_obj.get('id'))
if error: if error:
return error, _ return error, _
...@@ -180,9 +176,10 @@ class CreatePictorial(BaseView): ...@@ -180,9 +176,10 @@ class CreatePictorial(BaseView):
return error, None return error, None
if pictorial_comments: if pictorial_comments:
if platform == GRAP_PLATFORM.XIAOHONGSHU: if platform == GRAP_PLATFORM.XIAOHONGSHU:
error, _ = self.create_comment(comment_list=pictorial_comments, from_id=pictorial.get('id'), platform=platform, pictorial_id=pictorial_id) for pictorial_comment in pictorial_comments:
if error: error, _ = self.create_comment(comment_list=pictorial_comment, from_id=pictorial.get('id'), platform=platform, pictorial_id=pictorial_id)
return error, _ if error:
return error, _
return None, None return None, None
......
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