Commit 9192e464 authored by haowang's avatar haowang

fix code

parent 3be054ce
...@@ -91,7 +91,6 @@ class CreatePictorial(BaseView): ...@@ -91,7 +91,6 @@ class CreatePictorial(BaseView):
obj['from_id'] = from_id obj['from_id'] = from_id
obj['content'] = obj.get('comment') obj['content'] = obj.get('comment')
reply = obj.pop('reply', None) reply = obj.pop('reply', None)
ret.append(obj)
if not reply: if not reply:
continue continue
for info in reply: for info in reply:
...@@ -100,7 +99,25 @@ class CreatePictorial(BaseView): ...@@ -100,7 +99,25 @@ class CreatePictorial(BaseView):
info['type'] = obj.get('type') info['type'] = obj.get('type')
ret.append(info) 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): def create_topic(self, topics, platform):
for topic in topics: for topic in topics:
...@@ -115,63 +132,54 @@ class CreatePictorial(BaseView): ...@@ -115,63 +132,54 @@ 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:
topic_comments = self.revise_comments(topic_comments, from_id) error, _ = self.create_comment(comment_list=topic_comments, from_id=from_id, platform=platform, topic_id=topic_obj.get('id'))
for obj in topic_comments: if error:
obj['user_id'] = self.get_user_id(id_=obj.get('user').get('id'), platform=platform) return error, _
obj.pop('user')
error, _ = self.call_rpc('venus/community/crawl/replys', data=topic_comments, platform=platform, topic_id=topic_obj.get('id'))
if error:
return error, _
return None, None return None, None
def create_pictorial(self, pictorial, platform): def create_pictorial(self, pictorial, platform):
topics = [] topics = []
pictorial_id = None pictorial_id = None
if pictorial: if not pictorial:
pictorial_comments = pictorial.pop('comments', None) return None, None
images = self.image_info(pictorial.pop('image')) pictorial_comments = pictorial.pop('comments', None)
index = 0 images = self.image_info(pictorial.pop('image'))
for obj in images: index = 0
index += 1 for obj in images:
topics.append({ index += 1
'id': pictorial.get('id') + str(index), topics.append({
'content': pictorial.get('content'), 'id': pictorial.get('id') + str(index),
'images': [obj], 'content': pictorial.get('content'),
'create_time': pictorial.get('create_time'), 'images': [obj],
'user_id': self.get_user_id(id_=obj.get('url'), platform=platform) 'create_time': pictorial.get('create_time'),
}) 'user_id': self.get_user_id(id_=obj.get('url'), platform=platform)
})
pictorial['user_id'] = self.get_user_id(id_=pictorial.get('id'), platform=platform)
pictorial['description'] = pictorial.get('content') pictorial['user_id'] = self.get_user_id(id_=pictorial.get('id'), platform=platform)
pictorial['description'] = pictorial.get('content')
# 榜单名称取爬取内容的前20字符
index_end = 20 # 榜单名称取爬取内容的前20字符
if len(pictorial.get('content')) < index_end: index_end = 20
index_end = len(pictorial.get('content')) - 1 if len(pictorial.get('content')) < index_end:
index_end = len(pictorial.get('content')) - 1
pictorial['name'] = pictorial.get('content')[:index_end]
error, pictorial_obj = self.call_rpc('venus/community/crawl/pictorial', data=pictorial, platform=platform) pictorial['name'] = pictorial.get('content')[:index_end]
if error: error, pictorial_obj = self.call_rpc('venus/community/crawl/pictorial', data=pictorial, platform=platform)
return error, None if error:
pictorial_id = pictorial_obj.get('id') return error, None
pictorial_id = pictorial_obj.get('id')
if topics:
for obj in topics: if topics:
error, id_ = self.call_rpc('venus/community/crawl/topic', data=obj, platform=platform, pictorial_id=pictorial_id) 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)
if error: if error:
return error, None return error, None
if pictorial_comments:
if platform == GRAP_PLATFORM.XIAOHONGSHU:
error, _ = self.create_comment(comment_list=pictorial_comments, from_id=pictorial.get('id'), platform=platform, pictorial_id=pictorial_id)
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