Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
saturn
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
saturn
Commits
4c8c0bed
Commit
4c8c0bed
authored
Aug 05, 2019
by
haowang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix code
parent
de6deda4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
27 deletions
+54
-27
pictorial.py
api/views/pictorial.py
+54
-27
No files found.
api/views/pictorial.py
View file @
4c8c0bed
...
...
@@ -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
):
image_url
=
upload_image
(
url
)
while
not
image_url
:
def
image_info
(
self
,
url
s
):
ret
=
[]
for
url
in
urls
:
image_url
=
upload_image
(
url
)
width
,
height
=
self
.
get_image_size
(
image_url
)
while
not
width
and
not
height
:
while
not
image_url
:
image_url
=
upload_image
(
url
)
width
,
height
=
self
.
get_image_size
(
image_url
)
return
{
'url'
:
image_url
.
replace
(
'http://alpha.gmeiapp.com/'
,
''
),
'height'
:
height
,
'width'
:
width
,
}
while
not
width
and
not
height
:
width
,
height
=
self
.
get_image_size
(
image_url
)
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,35 +122,35 @@ 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
(
'image
s
'
):
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_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
)
if
error
:
self
.
del_cache
()
return
self
.
error
(
error
=
error
)
pictorial_id
=
pictorial_obj
.
get
(
'id'
)
if
pictorial_comments
:
error
,
_
=
self
.
call_rpc
(
'venus/community/crawl/replys'
,
data
=
pictorial_comments
,
platform
=
platform
,
pictorial_id
=
pictorial_id
)
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
)
if
error
:
self
.
del_cache
()
return
self
.
error
(
error
=
error
)
pictorial_id
=
pictorial_obj
.
get
(
'id'
)
if
pictorial_comments
:
error
,
_
=
self
.
call_rpc
(
'venus/community/crawl/replys'
,
data
=
pictorial_comments
,
platform
=
platform
,
pictorial_id
=
pictorial_id
)
if
error
:
self
.
del_cache
()
return
self
.
error
(
error
=
error
)
for
topic
in
topics
:
topic_comments
=
topic
.
pop
(
'comments'
,
None
)
image
=
topic
.
pop
(
'image
'
)
topic
[
'image
'
]
=
self
.
image_info
(
image
)
image
s
=
topic
.
pop
(
'images
'
)
topic
[
'image
s'
]
=
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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment