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
5abc8c42
Commit
5abc8c42
authored
Jan 22, 2019
by
王浩
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' into 'master'
alpha 1.10 See merge request
!16
parents
c475ced5
a29f0313
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
155 additions
and
9 deletions
+155
-9
urls.py
api/urls.py
+9
-0
read_excel.py
api/utils/read_excel.py
+2
-6
base_view.py
api/views/base_view.py
+16
-0
tag.py
api/views/tag.py
+0
-1
topic.py
api/views/topic.py
+94
-1
user.py
api/views/user.py
+21
-1
user.py
libs/user.py
+13
-0
No files found.
api/urls.py
View file @
5abc8c42
...
...
@@ -6,7 +6,16 @@ from .views import topic
from
.views
import
tag
urlpatterns
=
[
# grasp
url
(
r'^v1/update_grasp_status$'
,
user
.
UpdateGraspStatus
.
as_view
(),
name
=
'update_grasp_status$'
),
# topic
url
(
r'^v1/create_topic_for_batch$'
,
topic
.
CreateTopicForBatch
.
as_view
(),
name
=
'create_topic_for_batch'
),
url
(
r'^v1/create_topic_for_batch_by_one$'
,
topic
.
CreateTopicForBatchByOne
.
as_view
(),
name
=
'create_topic_for_batch_by_one'
),
# tag
url
(
r'^v1/create_tag_for_batch$'
,
tag
.
CreateTagForBatch
.
as_view
(),
name
=
'create_tag_for_batch'
),
# user
url
(
r'^v1/user/shadow/list$'
,
user
.
ShadowUserList
.
as_view
(),
name
=
'create_tag_for_batch'
),
]
api/utils/read_excel.py
View file @
5abc8c42
...
...
@@ -11,7 +11,7 @@ PAGE_SIZE = 100
def
read_excel
():
wb
=
open_workbook
(
filename
=
'/Users/
apple
/Desktop/nice_tag20181225.xlsx'
)
wb
=
open_workbook
(
filename
=
'/Users/
haowei
/Desktop/nice_tag20181225.xlsx'
)
sheet1
=
wb
.
sheet_by_index
(
0
)
...
...
@@ -27,7 +27,7 @@ def read_excel():
def
create_tags
(
tags
):
url
=
'http://
127.0.0.1:809
0/api/v1/create_tag_for_batch'
url
=
'http://
39.107.208.122:8
0/api/v1/create_tag_for_batch'
post_data
=
json
.
dumps
(
tags
)
textmod
=
{
"tags"
:
post_data
}
...
...
@@ -44,10 +44,6 @@ def process():
count
=
math
.
ceil
(
len
(
tags
)
/
PAGE_SIZE
)
print
(
count
)
for
i
in
range
(
0
,
count
):
if
i
==
5
:
break
if
i
<
4
:
continue
print
(
i
)
item
=
tags
[
PAGE_SIZE
*
i
:
PAGE_SIZE
*
i
+
PAGE_SIZE
]
# print(item, len(item))
...
...
api/views/base_view.py
View file @
5abc8c42
...
...
@@ -380,3 +380,19 @@ class BaseViewLoginRequired(LoginRequiredMixin, BaseView):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
BaseViewLoginRequired
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
get_offset_count
(
request
):
try
:
page
=
int
(
request
.
GET
.
get
(
'page'
,
1
))
except
:
page
=
1
try
:
count
=
int
(
request
.
GET
.
get
(
'count'
,
10
))
except
:
count
=
10
offset
=
count
*
(
page
-
1
)
return
offset
,
count
api/views/tag.py
View file @
5abc8c42
...
...
@@ -10,7 +10,6 @@ class CreateTagForBatch(BaseView):
"""
def
post
(
self
,
request
):
tag_list
=
json
.
loads
(
request
.
POST
.
get
(
"tags"
,
'[]'
))
print
(
request
.
POST
)
tags
=
[]
# 敏感词检测,获取可用的帖子
...
...
api/views/topic.py
View file @
5abc8c42
...
...
@@ -3,6 +3,8 @@ import json
from
api.views.base_view
import
BaseView
from
api.utils.sensitive
import
Sensitive
from
libs.user
import
get_user_by_ids
from
alpha_types.venus
import
ERROR
as
CODES
class
CreateTopicForBatch
(
BaseView
):
"""
...
...
@@ -11,11 +13,18 @@ class CreateTopicForBatch(BaseView):
def
post
(
self
,
request
):
user_id
=
request
.
POST
.
get
(
"user_id"
,
0
)
card_level
=
request
.
POST
.
get
(
"card_level"
,
0
)
tag_id
=
request
.
POST
.
get
(
"tag_id"
)
is_online
=
request
.
POST
.
get
(
"is_online"
,
0
)
topic_list
=
json
.
loads
(
request
.
POST
.
get
(
"topic_list"
,
'[]'
))
if
not
user_id
:
return
self
.
parameter_invalid_response
()
user_info
=
get_user_by_ids
([
user_id
])
if
not
user_info
:
return
self
.
error
(
self
.
get_ErrorInfo
(
CODES
.
USER_NOT_FOUND
))
if
not
topic_list
:
return
self
.
ok
()
...
...
@@ -23,9 +32,13 @@ class CreateTopicForBatch(BaseView):
# 敏感词检测,获取可用的帖子
check_info
=
Sensitive
.
check
([
topic
[
"content"
]
for
topic
in
topic_list
if
topic
.
get
(
"content"
)])
for
topic
in
topic_list
:
succ
=
check_info
.
get
(
topic
.
get
(
"content"
))
if
topic
.
get
(
"content"
)
else
True
if
topic
.
get
(
'content'
):
succ
=
check_info
.
get
(
topic
.
get
(
"content"
))
if
not
succ
:
topics
.
append
(
topic
)
else
:
if
topic
.
get
(
'images'
)
or
topic
.
get
(
'video'
):
topics
.
append
(
topic
)
if
not
topics
:
return
self
.
ok
()
...
...
@@ -35,6 +48,9 @@ class CreateTopicForBatch(BaseView):
tags
=
item
.
get
(
"tags"
)
or
[]
tag_names
.
extend
([
tag
.
replace
(
"#"
,
''
)
.
strip
()
for
tag
in
tags
])
item
[
"user_id"
]
=
user_id
item
[
"card_level"
]
=
card_level
item
[
"tag_id"
]
=
tag_id
item
[
"is_online"
]
=
is_online
check_info
=
Sensitive
.
check
(
tag_names
)
tags
=
[
tag_name
for
tag_name
,
succ
in
check_info
.
items
()
if
not
succ
]
...
...
@@ -72,3 +88,79 @@ class CreateTopicForBatch(BaseView):
return
self
.
error
(
create_err
)
return
self
.
ok
(
data
=
result
)
class
CreateTopicForBatchByOne
(
BaseView
):
"""
内部使用,一对一批量建帖
"""
def
post
(
self
,
request
):
user_ids
=
json
.
loads
(
request
.
POST
.
get
(
"user_ids"
,
'[]'
))
topic_list
=
json
.
loads
(
request
.
POST
.
get
(
"topic_list"
,
'[]'
))
if
not
user_ids
:
return
self
.
parameter_invalid_response
()
if
not
topic_list
:
return
self
.
ok
()
topics
=
[]
# 敏感词检测,获取可用的帖子
check_info
=
Sensitive
.
check
([
topic
[
"content"
]
for
topic
in
topic_list
if
topic
.
get
(
"content"
)])
for
topic
in
topic_list
:
if
topic
.
get
(
'content'
):
succ
=
check_info
.
get
(
topic
.
get
(
"content"
))
if
not
succ
:
topics
.
append
(
topic
)
else
:
if
topic
.
get
(
'images'
)
or
topic
.
get
(
'video'
):
topics
.
append
(
topic
)
if
not
topics
:
return
self
.
ok
()
tag_names
=
[]
need_create_topics
=
[]
for
item
,
user_id
in
zip
(
topics
,
user_ids
):
tags
=
item
.
get
(
"tags"
)
or
[]
tag_names
.
extend
([
tag
.
replace
(
"#"
,
''
)
.
strip
()
for
tag
in
tags
])
item
[
"user_id"
]
=
user_id
need_create_topics
.
append
(
item
)
check_info
=
Sensitive
.
check
(
tag_names
)
tags
=
[
tag_name
for
tag_name
,
succ
in
check_info
.
items
()
if
not
succ
]
# 先创建标签
_tag_error
,
_tag_data
=
self
.
call_rpc
(
"venus/community/tag/batch_create_tag_by_name"
,
tag_names
=
tags
)
if
_tag_error
:
return
self
.
error
(
_tag_error
)
# 更新发帖
# 处理标签,将文本中的标签处理成现有标签
for
item
in
need_create_topics
:
tags
=
item
.
get
(
"tags"
)
or
[]
tags
=
[
tag
.
replace
(
"#"
,
''
)
.
strip
()
for
tag
in
tags
]
content
=
item
[
"content"
]
for
tag_name
,
tag_id
in
_tag_data
.
items
():
if
tag_name
in
tags
:
alpha_tag
=
'<topic>{'
+
'"id":{},"name":"{}"'
.
format
(
tag_id
,
tag_name
)
+
'}</topic>'
content
=
content
.
replace
(
'#'
+
tag_name
,
alpha_tag
)
item
[
"content"
]
=
content
.
replace
(
'#'
,
''
)
item
[
"tag_ids"
]
=
[
_tag_data
[
tag_name
]
for
tag_name
in
tags
if
_tag_data
.
get
(
tag_name
)
]
create_err
,
result
=
self
.
call_rpc
(
"venus/community/topic/batch_create_for_inner"
,
topic_list
=
need_create_topics
)
if
create_err
:
return
self
.
error
(
create_err
)
return
self
.
ok
(
data
=
result
)
\ No newline at end of file
api/views/user.py
View file @
5abc8c42
from
api.views.base_view
import
BaseView
from
api.views.base_view
import
BaseView
,
get_offset_count
class
UpdateGraspStatus
(
BaseView
):
...
...
@@ -18,3 +18,23 @@ class UpdateGraspStatus(BaseView):
return
self
.
error
(
error
)
return
self
.
ok
(
data
=
_data
)
class
ShadowUserList
(
BaseView
):
'''
列表获取马甲用户
'''
def
get
(
self
,
request
):
offset
,
count
=
get_offset_count
(
request
)
error
,
_data
=
self
.
call_rpc
(
"venus/community/user/shadow/list"
,
offset
=
offset
,
count
=
count
)
if
error
:
return
self
.
error
(
error
)
users
=
_data
.
get
(
'users'
)
result
=
{
'users'
:
[{
'user_id'
:
item
.
get
(
'user_id'
)}
for
item
in
users
if
item
],
'total'
:
_data
.
get
(
'total'
)
}
return
self
.
ok
(
data
=
result
)
libs/user.py
View file @
5abc8c42
...
...
@@ -7,6 +7,7 @@ from helios.rpc import RPCFaultException
from
libs.utils
import
DictWrapperUseDot
from
engine.logger
import
auth_logger
from
engine.rpc
import
get_current_rpc_invoker
def
get_user_by_request
(
request
):
...
...
@@ -33,6 +34,18 @@ def get_user_by_request(request):
return
DictWrapperUseDot
(
info
)
def
get_user_by_ids
(
user_ids
):
"""获取用户信息"""
try
:
rpc
=
get_current_rpc_invoker
()
users_info
=
rpc
[
"venus/account/user/userinfo_list"
](
user_ids
=
user_ids
)
.
unwrap
()
except
:
return
None
return
users_info
def
auth
(
request
):
user_info
=
get_user_by_request
(
request
)
if
not
user_info
:
...
...
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