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
600da6e3
Commit
600da6e3
authored
Jan 02, 2019
by
王浩
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' into 'master'
Test See merge request
!4
parents
a92fd9f9
2615f6a8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
1 deletion
+106
-1
urls.py
api/urls.py
+2
-0
read_excel.py
api/utils/read_excel.py
+57
-0
sensitive.py
api/utils/sensitive.py
+5
-1
tag.py
api/views/tag.py
+28
-0
logger.py
engine/logger.py
+2
-0
log_settings.py
settings/log_settings.py
+12
-0
No files found.
api/urls.py
View file @
600da6e3
...
@@ -3,8 +3,10 @@ from django.conf.urls import url
...
@@ -3,8 +3,10 @@ from django.conf.urls import url
from
.views
import
user
from
.views
import
user
from
.views
import
topic
from
.views
import
topic
from
.views
import
tag
urlpatterns
=
[
urlpatterns
=
[
url
(
r'^v1/update_grasp_status$'
,
user
.
UpdateGraspStatus
.
as_view
(),
name
=
'update_grasp_status$'
),
url
(
r'^v1/update_grasp_status$'
,
user
.
UpdateGraspStatus
.
as_view
(),
name
=
'update_grasp_status$'
),
url
(
r'^v1/create_topic_for_batch$'
,
topic
.
CreateTopicForBatch
.
as_view
(),
name
=
'create_topic_for_batch'
),
url
(
r'^v1/create_topic_for_batch$'
,
topic
.
CreateTopicForBatch
.
as_view
(),
name
=
'create_topic_for_batch'
),
url
(
r'^v1/create_tag_for_batch$'
,
tag
.
CreateTagForBatch
.
as_view
(),
name
=
'create_tag_for_batch'
),
]
]
api/utils/read_excel.py
0 → 100644
View file @
600da6e3
from
xlrd
import
open_workbook
from
urllib.request
import
urlopen
,
Request
from
urllib
import
parse
import
json
import
math
import
requests
PAGE_SIZE
=
100
def
read_excel
():
wb
=
open_workbook
(
filename
=
'/Users/apple/Desktop/nice_tag20181225.xlsx'
)
sheet1
=
wb
.
sheet_by_index
(
0
)
tags
=
[]
for
i
in
range
(
1
,
sheet1
.
nrows
):
item
=
sheet1
.
row_values
(
i
)
if
item
:
if
item
[
1
]:
tags
.
append
({
'name'
:
item
[
1
],
'img'
:
item
[
-
1
]})
print
(
len
(
tags
))
return
tags
def
create_tags
(
tags
):
url
=
'http://127.0.0.1:8090/api/v1/create_tag_for_batch'
post_data
=
json
.
dumps
(
tags
)
textmod
=
{
"tags"
:
post_data
}
print
(
textmod
)
req
=
requests
.
post
(
url
=
url
,
data
=
textmod
)
print
(
req
.
text
)
def
process
():
tags
=
read_excel
()
# create_tags([{"name": "aaa", "img": "http://www.baidu.com"}, {"name": "bbb", "img": "http://www.baidu.com"}])
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))
create_tags
(
item
)
if
__name__
==
"__main__"
:
process
()
api/utils/sensitive.py
View file @
600da6e3
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
engine.rpc
import
get_current_rpc_invoker
from
engine.rpc
import
get_current_rpc_invoker
from
engine.logger
import
sensitive_logger
from
libs.spawn_task
import
SpawnTask
,
Task
from
libs.spawn_task
import
SpawnTask
,
Task
...
@@ -41,6 +42,9 @@ class Sensitive(object):
...
@@ -41,6 +42,9 @@ class Sensitive(object):
except
:
except
:
res
=
None
res
=
None
sensitive_logger
.
info
(
text
)
sensitive_logger
.
info
(
res
)
return
res
return
res
@classmethod
@classmethod
...
@@ -90,7 +94,7 @@ class Sensitive(object):
...
@@ -90,7 +94,7 @@ class Sensitive(object):
return
return
action
=
data
[
"result"
][
"action"
]
action
=
data
[
"result"
][
"action"
]
if
action
==
0
:
# "通过"
if
action
==
0
or
action
==
1
:
# "通过"
return
[]
return
[]
lables
=
data
.
get
(
"result"
,
{})
.
get
(
"labels"
,
[])
lables
=
data
.
get
(
"result"
,
{})
.
get
(
"labels"
,
[])
...
...
api/views/tag.py
0 → 100644
View file @
600da6e3
import
json
from
api.views.base_view
import
BaseView
from
api.utils.sensitive
import
Sensitive
class
CreateTagForBatch
(
BaseView
):
"""
内部使用,批量建标签
"""
def
post
(
self
,
request
):
tag_list
=
json
.
loads
(
request
.
POST
.
get
(
"tags"
,
'[]'
))
print
(
request
.
POST
)
tags
=
[]
# 敏感词检测,获取可用的帖子
check_info
=
Sensitive
.
check
([
item
[
"name"
]
for
item
in
tag_list
if
item
.
get
(
"name"
)])
for
tag
in
tag_list
:
succ
=
check_info
.
get
(
tag
.
get
(
"name"
))
if
tag
.
get
(
"name"
)
else
True
if
not
succ
:
tags
.
append
(
tag
)
error
,
data
=
self
.
call_rpc
(
'venus/community/tag/batch_create_not_classify'
,
data
=
tags
)
if
error
:
return
self
.
error
(
error
)
return
self
.
ok
(
data
=
data
)
engine/logger.py
View file @
600da6e3
...
@@ -27,6 +27,8 @@ exception_logger = logging.getLogger('exception_logger')
...
@@ -27,6 +27,8 @@ exception_logger = logging.getLogger('exception_logger')
cpc_click_consumer_logger
=
logging
.
getLogger
(
'cpc_click_consumer_logger'
)
cpc_click_consumer_logger
=
logging
.
getLogger
(
'cpc_click_consumer_logger'
)
auth_logger
=
logging
.
getLogger
(
'auth_logger'
)
auth_logger
=
logging
.
getLogger
(
'auth_logger'
)
wechat_logger
=
logging
.
getLogger
(
'wechat_logger'
)
wechat_logger
=
logging
.
getLogger
(
'wechat_logger'
)
sensitive_logger
=
logging
.
getLogger
(
'sensitive_logger'
)
def
debug
(
view_func
):
def
debug
(
view_func
):
"""将POST请求数据存到log
"""将POST请求数据存到log
...
...
settings/log_settings.py
View file @
600da6e3
...
@@ -92,6 +92,13 @@ LOGGING = {
...
@@ -92,6 +92,13 @@ LOGGING = {
'interval'
:
1
,
'interval'
:
1
,
'backupCount'
:
30
,
'backupCount'
:
30
,
},
},
'sensitive_handler'
:
{
'level'
:
'INFO'
,
'class'
:
'logging.handlers.RotatingFileHandler'
,
'filename'
:
os
.
path
.
join
(
LOG_DIR
,
'sensitive.log'
),
'formatter'
:
'profile'
,
'maxBytes'
:
500
*
1024
*
1024
,
# 500M
},
},
},
'loggers'
:
{
'loggers'
:
{
...
@@ -143,6 +150,11 @@ LOGGING = {
...
@@ -143,6 +150,11 @@ LOGGING = {
'propagate'
:
False
,
'propagate'
:
False
,
'level'
:
'INFO'
'level'
:
'INFO'
},
},
'sensitive_logger'
:
{
'handlers'
:
[
'sensitive_handler'
],
'propagate'
:
False
,
'level'
:
'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