Commit 4c8c0bed authored by haowang's avatar haowang

fix code

parent de6deda4
......@@ -28,7 +28,7 @@ class CreatePictorial(BaseView):
ins_cache.delete(obj)
def get_random_user_id(self):
index = randint(0, 4)
index = randint(0, 3)
return self.user_id_list[index]
def get_user_id(self, id_, platform):
......@@ -62,24 +62,46 @@ class CreatePictorial(BaseView):
logging_exception()
return None
def image_info(self, url):
def image_info(self, urls):
ret = []
for url in urls:
image_url = upload_image(url)
while not image_url:
image_url = upload_image(url)
width, height = self.get_image_size(image_url)
while not width and not height:
width, height = self.get_image_size(image_url)
return {
ret.append(
{
'url': image_url.replace('http://alpha.gmeiapp.com/', ''),
'height': height,
'width': width,
}
)
return ret
def revise_comments(self, comments, from_id):
ret = []
for obj in comments:
obj['from_id'] = from_id
reply = obj.pop('reply', None)
if not reply:
ret.append(obj)
continue
for info in reply:
ret.append(obj)
info['from_id'] = obj.get('from_id')
info['reply_id'] = obj.get('id')
info['type'] = obj.get('type')
ret.append(info)
return ret
def post(self, request):
pictorial = json.loads(request.POST.get('pictorial', '{}'))
topics = json.loads(request.POST.get('topics', '[]'))
platform = request.POST.get('platform', GRAP_PLATFORM.XIAOHONGSHU)
platform = int(request.POST.get('platform', GRAP_PLATFORM.XIAOHONGSHU))
if not topics:
return self.error(self.get_ErrorInfo(ERROR.PARAMS_INCOMPLETE))
......@@ -100,17 +122,17 @@ class CreatePictorial(BaseView):
for topic in topics:
if not topic.get('id'):
return self.error(self.get_ErrorInfo(ERROR.PARAMS_INCOMPLETE))
if not topic.get('from_id'):
return self.error(self.get_ErrorInfo(ERROR.PARAMS_INCOMPLETE))
if not topic.get('content'):
return self.error(self.get_ErrorInfo(ERROR.PARAMS_INCOMPLETE))
if not topic.get('image'):
if not topic.get('images'):
return self.error(self.get_ErrorInfo(ERROR.PARAMS_INCOMPLETE))
if not topic.get('create_time'):
return self.error(self.get_ErrorInfo(ERROR.PARAMS_INCOMPLETE))
if not topic.get('user').get('id'):
return self.error(self.get_ErrorInfo(ERROR.PARAMS_INCOMPLETE))
pictorial_id = None
if pictorial:
pictorial_comments = pictorial.pop('comments', None)
pictorial['user_id'] = self.get_user_id(id_=pictorial.get('id'), platform=platform)
error, pictorial_obj = self.call_rpc('venus/community/crawl/pictorial', data=pictorial, platform=platform)
......@@ -127,8 +149,8 @@ class CreatePictorial(BaseView):
for topic in topics:
topic_comments = topic.pop('comments', None)
image = topic.pop('image')
topic['image'] = self.image_info(image)
images = topic.pop('images')
topic['images'] = self.image_info(images)
topic['user_id'] = self.get_user_id(id_=topic.get('id'), platform=platform)
error, topic_obj = self.call_rpc('venus/community/crawl/topic', data=topic, platform=platform, pictorial_id=pictorial_id)
if error:
......@@ -136,7 +158,12 @@ class CreatePictorial(BaseView):
return self.error(error=error)
if not topic_comments:
continue
import ipdb
ipdb.set_trace()
from_id = topic.get('id')
for obj in topic_comments:
if platform == GRAP_PLATFORM.XIAOHONGSHU:
topic_comments = self.revise_comments(topic_comments, from_id)
obj['user_id'] = self.get_user_id(id_=obj.get('id'), platform=platform)
error, _ = self.call_rpc('venus/community/crawl/replys', data=topic_comments, platform=platform, topic_id=topic_obj.get('id'))
if error:
......
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