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
dd262629
Commit
dd262629
authored
Sep 19, 2019
by
zhongshangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复小红书入库马甲用户逻辑
parent
3bffffdb
Pipeline
#1978
passed with stage
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
23 deletions
+33
-23
reply_commands.py
api/management/commands/reply_commands.py
+33
-23
No files found.
api/management/commands/reply_commands.py
View file @
dd262629
...
@@ -3,6 +3,7 @@ import os
...
@@ -3,6 +3,7 @@ import os
from
datetime
import
datetime
from
datetime
import
datetime
import
json
import
json
import
requests
import
requests
import
random
from
random
import
randint
from
random
import
randint
from
django.core.management
import
BaseCommand
from
django.core.management
import
BaseCommand
from
engine.rpc
import
rpc_invoker
from
engine.rpc
import
rpc_invoker
...
@@ -16,7 +17,7 @@ from engine.logger import info_logger, error_logger, logging_exception
...
@@ -16,7 +17,7 @@ from engine.logger import info_logger, error_logger, logging_exception
IMAGE_SUFFIX
=
'-w'
IMAGE_SUFFIX
=
'-w'
FILE_PATH
=
'/Users/
haowei/Desktop/xhs
/'
FILE_PATH
=
'/Users/
zhongshangwu/workspace/gengmei/like/saturn/xiaohongshu
/'
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
...
@@ -27,7 +28,7 @@ class Command(BaseCommand):
...
@@ -27,7 +28,7 @@ class Command(BaseCommand):
del_cache_keys
=
[]
del_cache_keys
=
[]
create_faild_topic_list
=
[]
create_faild_topic_list
=
[]
create_faild_pictorial_list
=
[]
create_faild_pictorial_list
=
[]
top_comment_error_create
=
[]
top_comment_error_create
=
[]
second_topic_comments
=
[]
second_topic_comments
=
[]
...
@@ -37,23 +38,32 @@ class Command(BaseCommand):
...
@@ -37,23 +38,32 @@ class Command(BaseCommand):
second_pictorial_error_comments
=
[]
second_pictorial_error_comments
=
[]
second_reply_error_create
=
[]
second_reply_error_create
=
[]
shadow_user_ids
=
[]
def
del_cache
(
self
):
def
del_cache
(
self
):
for
obj
in
self
.
del_cache_keys
:
for
obj
in
self
.
del_cache_keys
:
ins_cache
.
delete
(
obj
)
ins_cache
.
delete
(
obj
)
def
load_shadow_users
(
self
):
data
=
rpc_invoker
[
'venus/community/crawl/load_shawdow_user'
](
start_user_id
=
self
.
user_id_start
,
end_user_id
=
self
.
user_id_start
+
5000
)
.
unwrap
()
print
(
data
,
">>>>>"
)
self
.
shadow_user_ids
=
data
def
get_random_user_id
(
self
):
def
get_random_user_id
(
self
):
# 随机获取用户ID
# 随机获取用户ID
while
True
:
return
random
.
choice
(
self
.
shadow_user_ids
)
index
=
randint
(
0
,
5000
)
# while True:
user_id
=
self
.
user_id_start
+
index
# index = randint(0, 5000)
data
=
rpc_invoker
[
'venus/community/user/is_shadow'
](
user_id
=
user_id
)
.
unwrap
()
# user_id = self.user_id_start + index
if
not
data
:
# data = rpc_invoker['venus/community/user/is_shadow'](user_id=user_id).unwrap()
continue
# if not data:
ret
=
data
.
get
(
'user_id'
)
# continue
if
ret
:
# ret = data.get('user_id')
return
user_id
# if ret:
# return user_id
def
get_user_id
(
self
,
id_
,
platform
):
def
get_user_id
(
self
,
id_
,
platform
):
# 获取用户ID 缓存记录保留用户关系
# 获取用户ID 缓存记录保留用户关系
...
@@ -85,12 +95,12 @@ class Command(BaseCommand):
...
@@ -85,12 +95,12 @@ class Command(BaseCommand):
filenames
=
[]
filenames
=
[]
for
_
,
_
,
names
in
os
.
walk
(
file_path
):
for
_
,
_
,
names
in
os
.
walk
(
file_path
):
filenames
=
names
filenames
=
names
for
filename
in
filenames
:
for
filename
in
filenames
:
ret
.
append
(
self
.
get_file_json_data
(
file_path
+
filename
))
ret
.
append
(
self
.
get_file_json_data
(
file_path
+
filename
))
return
ret
return
ret
def
get_file_json_data
(
self
,
file
):
def
get_file_json_data
(
self
,
file
):
# 获取文件数据
# 获取文件数据
data
=
None
data
=
None
...
@@ -98,9 +108,9 @@ class Command(BaseCommand):
...
@@ -98,9 +108,9 @@ class Command(BaseCommand):
content
=
f
.
read
()
content
=
f
.
read
()
if
content
.
startswith
(
u'
\ufeff
'
):
if
content
.
startswith
(
u'
\ufeff
'
):
content
=
content
.
encode
(
'utf8'
)[
3
:]
.
decode
(
'utf8'
)
content
=
content
.
encode
(
'utf8'
)[
3
:]
.
decode
(
'utf8'
)
data
=
json
.
loads
(
content
)
data
=
json
.
loads
(
content
)
return
data
return
data
def
get_image_size
(
self
,
image_url
):
def
get_image_size
(
self
,
image_url
):
...
@@ -142,7 +152,7 @@ class Command(BaseCommand):
...
@@ -142,7 +152,7 @@ class Command(BaseCommand):
for
info
in
reply
:
for
info
in
reply
:
info
[
'reply_id'
]
=
comment
.
get
(
'id'
)
info
[
'reply_id'
]
=
comment
.
get
(
'id'
)
info
[
'type'
]
=
comment
.
get
(
'type'
)
info
[
'type'
]
=
comment
.
get
(
'type'
)
ret
.
append
(
info
)
ret
.
append
(
info
)
return
comment
,
ret
return
comment
,
ret
...
@@ -187,7 +197,7 @@ class Command(BaseCommand):
...
@@ -187,7 +197,7 @@ class Command(BaseCommand):
obj
[
'user_id'
]
=
self
.
get_user_id
(
id_
=
obj
.
get
(
'user'
)
.
get
(
'id'
),
platform
=
platform
)
obj
[
'user_id'
]
=
self
.
get_user_id
(
id_
=
obj
.
get
(
'user'
)
.
get
(
'id'
),
platform
=
platform
)
obj
[
'top_id'
]
=
top_id
obj
[
'top_id'
]
=
top_id
obj
.
pop
(
'user'
)
obj
.
pop
(
'user'
)
# rpc_invoker['venus/community/crawl/replys'](data=comments, platform=platform, topic_id=topic_id, pictorial_id=pictorial_id, top_id=top_id).unwrap()
# rpc_invoker['venus/community/crawl/replys'](data=comments, platform=platform, topic_id=topic_id, pictorial_id=pictorial_id, top_id=top_id).unwrap()
self
.
second_topic_comments
.
extend
(
comments
)
self
.
second_topic_comments
.
extend
(
comments
)
# print('-------- topic_comments:', self.second_topic_comments)
# print('-------- topic_comments:', self.second_topic_comments)
...
@@ -211,7 +221,7 @@ class Command(BaseCommand):
...
@@ -211,7 +221,7 @@ class Command(BaseCommand):
'create_time'
:
pictorial
.
get
(
'create_time'
),
'create_time'
:
pictorial
.
get
(
'create_time'
),
'user_id'
:
self
.
get_user_id
(
id_
=
obj
.
get
(
'url'
),
platform
=
platform
)
'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
[
'user_id'
]
=
self
.
get_user_id
(
id_
=
pictorial
.
get
(
'id'
),
platform
=
platform
)
pictorial
[
'description'
]
=
pictorial
.
get
(
'content'
)
pictorial
[
'description'
]
=
pictorial
.
get
(
'content'
)
...
@@ -248,14 +258,14 @@ class Command(BaseCommand):
...
@@ -248,14 +258,14 @@ class Command(BaseCommand):
obj
[
'user_id'
]
=
self
.
get_user_id
(
id_
=
obj
.
get
(
'user'
)
.
get
(
'id'
),
platform
=
platform
)
obj
[
'user_id'
]
=
self
.
get_user_id
(
id_
=
obj
.
get
(
'user'
)
.
get
(
'id'
),
platform
=
platform
)
obj
[
'top_id'
]
=
top_id
obj
[
'top_id'
]
=
top_id
obj
.
pop
(
'user'
)
obj
.
pop
(
'user'
)
# rpc_invoker['venus/community/crawl/replys'](data=comments, platform=platform, topic_id=topic_id, pictorial_id=pictorial_id, top_id=top_id).unwrap()
# rpc_invoker['venus/community/crawl/replys'](data=comments, platform=platform, topic_id=topic_id, pictorial_id=pictorial_id, top_id=top_id).unwrap()
self
.
second_pictorial_comments
.
extend
(
comments
)
self
.
second_pictorial_comments
.
extend
(
comments
)
return
None
,
None
return
None
,
None
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
self
.
load_shadow_users
()
platform
=
4
platform
=
4
# 帖子
# 帖子
print
(
'----- start deal topic at {} -----'
.
format
(
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S
%
f'
)))
print
(
'----- start deal topic at {} -----'
.
format
(
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S
%
f'
)))
...
@@ -264,7 +274,7 @@ class Command(BaseCommand):
...
@@ -264,7 +274,7 @@ class Command(BaseCommand):
print
(
'-------- create_faild_topic_list:'
,
len
(
self
.
create_faild_topic_list
))
print
(
'-------- create_faild_topic_list:'
,
len
(
self
.
create_faild_topic_list
))
print
(
'-------- second_topic_comments:'
,
len
(
self
.
second_topic_comments
))
print
(
'-------- second_topic_comments:'
,
len
(
self
.
second_topic_comments
))
print
(
'----- end deal topic at {} -----'
.
format
(
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S
%
f'
)))
print
(
'----- end deal topic at {} -----'
.
format
(
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S
%
f'
)))
# 榜单
# 榜单
print
(
'----- start deal pictorial at {} -----'
.
format
(
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S
%
f'
)))
print
(
'----- start deal pictorial at {} -----'
.
format
(
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S
%
f'
)))
pictorial_data
=
self
.
get_json_data_from_dir
(
is_pictorial
=
1
)
pictorial_data
=
self
.
get_json_data_from_dir
(
is_pictorial
=
1
)
...
...
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