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
9192e464
Commit
9192e464
authored
Aug 09, 2019
by
haowang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix code
parent
3be054ce
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
51 deletions
+59
-51
pictorial.py
api/views/pictorial.py
+59
-51
No files found.
api/views/pictorial.py
View file @
9192e464
...
...
@@ -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,63 +132,54 @@ 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'
))
if
error
:
return
error
,
_
error
,
_
=
self
.
create_comment
(
comment_list
=
topic_comments
,
from_id
=
from_id
,
platform
=
platform
,
topic_id
=
topic_obj
.
get
(
'id'
))
if
error
:
return
error
,
_
return
None
,
None
def
create_pictorial
(
self
,
pictorial
,
platform
):
topics
=
[]
pictorial_id
=
None
if
pictorial
:
pictorial_comments
=
pictorial
.
pop
(
'comments'
,
None
)
images
=
self
.
image_info
(
pictorial
.
pop
(
'image'
))
index
=
0
for
obj
in
images
:
index
+=
1
topics
.
append
({
'id'
:
pictorial
.
get
(
'id'
)
+
str
(
index
),
'content'
:
pictorial
.
get
(
'content'
),
'images'
:
[
obj
],
'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'
)
# 榜单名称取爬取内容的前20字符
index_end
=
20
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
)
if
error
:
return
error
,
None
pictorial_id
=
pictorial_obj
.
get
(
'id'
)
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
)
if
not
pictorial
:
return
None
,
None
pictorial_comments
=
pictorial
.
pop
(
'comments'
,
None
)
images
=
self
.
image_info
(
pictorial
.
pop
(
'image'
))
index
=
0
for
obj
in
images
:
index
+=
1
topics
.
append
({
'id'
:
pictorial
.
get
(
'id'
)
+
str
(
index
),
'content'
:
pictorial
.
get
(
'content'
),
'images'
:
[
obj
],
'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'
)
# 榜单名称取爬取内容的前20字符
index_end
=
20
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
)
if
error
:
return
error
,
None
pictorial_id
=
pictorial_obj
.
get
(
'id'
)
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
:
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
...
...
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