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
1
Merge Requests
1
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
alpha
saturn
Commits
af05f4f6
Commit
af05f4f6
authored
Aug 08, 2019
by
王浩
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'haow/dev' into 'test'
fix code See merge request
!88
parents
2b919606
7fd8ac80
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
47 deletions
+89
-47
pictorial.py
api/views/pictorial.py
+89
-47
No files found.
api/views/pictorial.py
View file @
af05f4f6
...
@@ -20,7 +20,7 @@ class CreatePictorial(BaseView):
...
@@ -20,7 +20,7 @@ class CreatePictorial(BaseView):
"""
"""
画报爬取接口
画报爬取接口
"""
"""
user_id_start
=
241
806255
# end 241757306
user_id_start
=
241
757306
# end 241806255
del_cache_keys
=
[]
del_cache_keys
=
[]
def
del_cache
(
self
):
def
del_cache
(
self
):
...
@@ -84,6 +84,7 @@ class CreatePictorial(BaseView):
...
@@ -84,6 +84,7 @@ class CreatePictorial(BaseView):
ret
=
[]
ret
=
[]
for
obj
in
comments
:
for
obj
in
comments
:
obj
[
'from_id'
]
=
from_id
obj
[
'from_id'
]
=
from_id
obj
[
'content'
]
=
obj
.
get
(
'comment'
)
reply
=
obj
.
pop
(
'reply'
,
None
)
reply
=
obj
.
pop
(
'reply'
,
None
)
if
not
reply
:
if
not
reply
:
ret
.
append
(
obj
)
ret
.
append
(
obj
)
...
@@ -97,27 +98,93 @@ class CreatePictorial(BaseView):
...
@@ -97,27 +98,93 @@ class CreatePictorial(BaseView):
ret
.
append
(
info
)
ret
.
append
(
info
)
return
ret
return
ret
def
create_topic
(
self
,
topics
,
platform
):
for
topic
in
topics
:
topic_comments
=
topic
.
pop
(
'comments'
,
None
)
images
=
topic
.
pop
(
'image'
)
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
=
None
)
if
error
:
self
.
del_cache
()
return
self
.
error
(
error
=
error
)
if
not
topic_comments
:
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
(
'id'
),
platform
=
platform
)
error
,
_
=
self
.
call_rpc
(
'venus/community/crawl/replys'
,
data
=
topic_comments
,
platform
=
platform
,
topic_id
=
topic_obj
.
get
(
'id'
))
if
error
:
self
.
del_cache
()
return
self
.
error
(
error
=
error
)
self
.
del_cache
()
return
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'
),
'image'
:
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
:
self
.
del_cache
()
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
:
self
.
del_cache
()
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
(
'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
:
self
.
del_cache
()
return
error
,
None
self
.
del_cache
()
return
None
,
None
def
post
(
self
,
request
):
def
post
(
self
,
request
):
pictorial
=
json
.
loads
(
request
.
POST
.
get
(
'pictorial'
,
'{}'
))
topics
=
json
.
loads
(
request
.
POST
.
get
(
'topics'
,
'[]'
))
topics
=
json
.
loads
(
request
.
POST
.
get
(
'topics'
,
'[]'
))
platform
=
int
(
request
.
POST
.
get
(
'platform'
,
GRAP_PLATFORM
.
XIAOHONGSHU
))
platform
=
int
(
request
.
POST
.
get
(
'platform'
,
GRAP_PLATFORM
.
XIAOHONGSHU
))
is_pictorial
=
request
.
POST
.
get
(
'is_pictorial'
,
None
)
if
not
topics
:
if
not
topics
:
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
if
pictorial
:
if
not
pictorial
.
get
(
'id'
):
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
if
not
pictorial
.
get
(
'name'
):
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
if
not
pictorial
.
get
(
'description'
):
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
if
not
pictorial
.
get
(
'create_time'
):
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
if
not
pictorial
.
get
(
'user'
):
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
if
not
pictorial
.
get
(
'user'
)
.
get
(
'id'
):
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
for
topic
in
topics
:
for
topic
in
topics
:
if
not
topic
.
get
(
'id'
):
if
not
topic
.
get
(
'id'
):
...
@@ -131,41 +198,16 @@ class CreatePictorial(BaseView):
...
@@ -131,41 +198,16 @@ class CreatePictorial(BaseView):
if
not
topic
.
get
(
'user'
)
.
get
(
'id'
):
if
not
topic
.
get
(
'user'
)
.
get
(
'id'
):
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
pictorial_id
=
None
if
is_pictorial
:
if
pictorial
:
is_pictorial
=
int
(
is_pictorial
)
pictorial_comments
=
pictorial
.
pop
(
'comments'
,
None
)
if
is_pictorial
:
pictorial
[
'user_id'
]
=
self
.
get_user_id
(
id_
=
pictorial
.
get
(
'id'
),
platform
=
platform
)
for
obj
in
topics
:
error
,
pictorial_obj
=
self
.
call_rpc
(
'venus/community/crawl/pictorial'
,
data
=
pictorial
,
platform
=
platform
)
error
,
_
=
self
.
create_pictorial
(
pictorial
=
obj
,
platform
=
platform
)
if
error
:
if
error
:
self
.
del_cache
()
return
self
.
error
(
error
=
error
)
return
self
.
error
(
error
=
error
)
pictorial_id
=
pictorial_obj
.
get
(
'id'
)
else
:
error
,
_
=
self
.
create_topic
(
topics
=
topics
,
platform
=
platform
)
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
)
images
=
topic
.
pop
(
'image'
)
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
:
self
.
del_cache
()
return
self
.
error
(
error
=
error
)
if
not
topic_comments
:
continue
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
:
if
error
:
self
.
del_cache
()
return
self
.
error
(
error
=
error
)
return
self
.
error
(
error
=
error
)
self
.
del_cache
()
self
.
del_cache
()
...
...
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