Commit 9192e464 authored by haowang's avatar haowang

fix code

parent 3be054ce
......@@ -91,7 +91,6 @@ class CreatePictorial(BaseView):
obj['from_id'] = from_id
obj['content'] = obj.get('comment')
reply = obj.pop('reply', None)
ret.append(obj)
if not reply:
continue
for info in reply:
......@@ -100,7 +99,25 @@ class CreatePictorial(BaseView):
info['type'] = obj.get('type')
ret.append(info)
return ret
return obj, ret
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['user_id'] = self.get_user_id(id_=top_comment.get('user').get('id'), platform=platform)
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)
if error:
return error, ret
top_id = ret.get('reply_ids')[0]
for obj in comments:
obj['user_id'] = self.get_user_id(id_=obj.get('user').get('id'), platform=platform)
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)
if error:
return error, _
def create_topic(self, topics, platform):
for topic in topics:
......@@ -115,11 +132,7 @@ class CreatePictorial(BaseView):
continue
from_id = topic.get('id')
if platform == GRAP_PLATFORM.XIAOHONGSHU:
topic_comments = self.revise_comments(topic_comments, from_id)
for obj in topic_comments:
obj['user_id'] = self.get_user_id(id_=obj.get('user').get('id'), platform=platform)
obj.pop('user')
error, _ = self.call_rpc('venus/community/crawl/replys', data=topic_comments, platform=platform, topic_id=topic_obj.get('id'))
error, _ = self.create_comment(comment_list=topic_comments, from_id=from_id, platform=platform, topic_id=topic_obj.get('id'))
if error:
return error, _
......@@ -128,7 +141,8 @@ class CreatePictorial(BaseView):
def create_pictorial(self, pictorial, platform):
topics = []
pictorial_id = None
if pictorial:
if not pictorial:
return None, None
pictorial_comments = pictorial.pop('comments', None)
images = self.image_info(pictorial.pop('image'))
index = 0
......@@ -159,19 +173,13 @@ class CreatePictorial(BaseView):
if topics:
for obj in topics:
error, id_ = self.call_rpc('venus/community/crawl/topic', data=obj, platform=platform, pictorial_id=pictorial_id)
if error:
return error, None
if pictorial_comments:
if platform == GRAP_PLATFORM.XIAOHONGSHU:
pictorial_comments = self.revise_comments(pictorial_comments, pictorial.get('id'))
for obj in pictorial_comments:
obj['user_id'] = self.get_user_id(id_=obj.get('user').get('id'), platform=platform)
obj.pop('user')
error, _ = self.call_rpc('venus/community/crawl/replys', data=pictorial_comments, platform=platform, pictorial_id=pictorial_id)
error, _ = self.create_comment(comment_list=pictorial_comments, from_id=pictorial.get('id'), platform=platform, pictorial_id=pictorial_id)
if error:
return error, None
return error, _
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