Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
V
vest
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
2
Merge Requests
2
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
rank
vest
Commits
11f9cc91
Commit
11f9cc91
authored
Jan 02, 2020
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增类型
parent
51fb4d05
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
44 deletions
+115
-44
comment_fun.py
comment/views/comment_fun.py
+78
-21
irrigation.py
moment/views/irrigation.py
+37
-23
No files found.
comment/views/comment_fun.py
View file @
11f9cc91
...
@@ -8,29 +8,86 @@ from moment.views.send_email import send_email_tome
...
@@ -8,29 +8,86 @@ from moment.views.send_email import send_email_tome
def
comment
(
card_info
):
def
comment
(
card_info
):
"""
在这里需要判断是帖子下发评论还是问答还是日记下发
:param card_info:
:return:
"""
try
:
try
:
key
=
"auto_vest_one_user_action:"
+
str
(
card_info
[
'card_id'
])
if
card_info
[
'card_status'
]
==
'tractate'
:
redis_data
=
redis_client
.
get
(
key
)
key
=
"tractate_auto_vest_one_user_action:"
+
str
(
card_info
[
'card_id'
])
if
redis_data
:
redis_data
=
redis_client
.
get
(
key
)
redis_data
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf8"
))
if
redis_data
:
click_num
=
int
(
redis_data
.
get
(
"comment"
))
+
1
redis_data
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf8"
))
redis_data
[
'comment'
]
=
click_num
click_num
=
int
(
redis_data
.
get
(
"comment"
))
+
1
redis_client
.
set
(
key
,
json
.
dumps
(
redis_data
))
redis_data
[
'comment'
]
=
click_num
else
:
redis_client
.
set
(
key
,
json
.
dumps
(
redis_data
))
redis_data
=
{
"click"
:
0
,
"follow"
:
0
,
"comment"
:
1
}
else
:
redis_client
.
set
(
key
,
json
.
dumps
(
redis_data
))
redis_data
=
{
"comment"
:
1
}
redis_client
.
expire
(
key
,
time
=
24
*
60
*
60
)
redis_client
.
set
(
key
,
json
.
dumps
(
redis_data
))
logging
.
info
(
"get action:comment,card_id:
%
s,redis_data:
%
s"
%
(
card_info
[
'card_id'
],
redis_data
))
redis_client
.
expire
(
key
,
time
=
24
*
60
*
60
)
comment_num
=
redis_data
[
"comment"
]
logging
.
info
(
"get action:comment,card_id:
%
s,redis_data:
%
s"
%
(
card_info
[
'card_id'
],
redis_data
))
####在这里做判断 一天不能超过20个 如果超过二十个不下发 不超过二十个下发对应的灌水功能
comment_num
=
redis_data
[
"comment"
]
if
comment_num
>
20
:
return
True
####在这里做判断 一天不能超过20个 如果超过二十个不下发 不超过二十个下发对应的灌水功能
# send_email_tome(str(redis_data) + str(card_info))
if
comment_num
>
20
:
return
True
# send_email_tome(str(redis_data) + str(card_info))
else
:
rpc_invoker
=
get_rpc_invoker
()
rpc_invoker
[
'qa/irrigation/create_answer_reply'
](
user_id
=
card_info
[
'current_user_id'
],
answer_id
=
card_info
[
'card_id'
],
content
=
card_info
[
'comment_content'
])
.
unwrap
()
elif
card_info
[
'card_status'
]
==
'diary'
:
key
=
"diary_auto_vest_one_user_action:"
+
str
(
card_info
[
'card_id'
])
redis_data
=
redis_client
.
get
(
key
)
if
redis_data
:
redis_data
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf8"
))
click_num
=
int
(
redis_data
.
get
(
"comment"
))
+
1
redis_data
[
'comment'
]
=
click_num
redis_client
.
set
(
key
,
json
.
dumps
(
redis_data
))
else
:
redis_data
=
{
"comment"
:
1
}
redis_client
.
set
(
key
,
json
.
dumps
(
redis_data
))
redis_client
.
expire
(
key
,
time
=
24
*
60
*
60
)
logging
.
info
(
"get action:comment,card_id:
%
s,redis_data:
%
s"
%
(
card_info
[
'card_id'
],
redis_data
))
comment_num
=
redis_data
[
"comment"
]
####在这里做判断 一天不能超过20个 如果超过二十个不下发 不超过二十个下发对应的灌水功能
if
comment_num
>
20
:
return
True
# send_email_tome(str(redis_data) + str(card_info))
else
:
rpc_invoker
=
get_rpc_invoker
()
rpc_invoker
[
'qa/irrigation/create_answer_reply'
](
user_id
=
card_info
[
'current_user_id'
],
answer_id
=
card_info
[
'card_id'
],
content
=
card_info
[
'comment_content'
])
.
unwrap
()
else
:
else
:
rpc_invoker
=
get_rpc_invoker
()
key
=
"auto_vest_one_user_action:"
+
str
(
card_info
[
'card_id'
])
rpc_invoker
[
'qa/irrigation/create_answer_reply'
](
user_id
=
card_info
[
'current_user_id'
],
redis_data
=
redis_client
.
get
(
key
)
answer_id
=
card_info
[
'card_id'
],
if
redis_data
:
content
=
card_info
[
'comment_content'
])
.
unwrap
()
redis_data
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf8"
))
click_num
=
int
(
redis_data
.
get
(
"comment"
))
+
1
redis_data
[
'comment'
]
=
click_num
redis_client
.
set
(
key
,
json
.
dumps
(
redis_data
))
else
:
redis_data
=
{
"click"
:
0
,
"follow"
:
0
,
"comment"
:
1
}
redis_client
.
set
(
key
,
json
.
dumps
(
redis_data
))
redis_client
.
expire
(
key
,
time
=
24
*
60
*
60
)
logging
.
info
(
"get action:comment,card_id:
%
s,redis_data:
%
s"
%
(
card_info
[
'card_id'
],
redis_data
))
comment_num
=
redis_data
[
"comment"
]
####在这里做判断 一天不能超过20个 如果超过二十个不下发 不超过二十个下发对应的灌水功能
if
comment_num
>
20
:
return
True
# send_email_tome(str(redis_data) + str(card_info))
else
:
rpc_invoker
=
get_rpc_invoker
()
rpc_invoker
[
'qa/irrigation/create_answer_reply'
](
user_id
=
card_info
[
'current_user_id'
],
answer_id
=
card_info
[
'card_id'
],
content
=
card_info
[
'comment_content'
])
.
unwrap
()
return
True
return
True
except
:
except
:
logging_exception
()
logging_exception
()
...
...
moment/views/irrigation.py
View file @
11f9cc91
...
@@ -14,6 +14,16 @@ from libs.error import logging_exception
...
@@ -14,6 +14,16 @@ from libs.error import logging_exception
@bind
(
'vest/moment/vest_irrigation'
)
@bind
(
'vest/moment/vest_irrigation'
)
def
vest_irrigation
(
card_id
=
0
,
card_type
=
None
,
card_user_id
=
None
,
create_time
=
""
,
content_level
=
0
,
tag_names
=
[]):
def
vest_irrigation
(
card_id
=
0
,
card_type
=
None
,
card_user_id
=
None
,
create_time
=
""
,
content_level
=
0
,
tag_names
=
[]):
"""
在这里把后端传的数据存进卡夫卡 日记和帖子只需要发评论不需要点赞和关注
:param card_id:
:param card_type:
:param card_user_id:
:param create_time:
:param content_level:
:param tag_names:
:return:
"""
try
:
try
:
producer
=
KafkaProducer
(
bootstrap_servers
=
settings
.
KAFKA_BROKER_LIST
)
producer
=
KafkaProducer
(
bootstrap_servers
=
settings
.
KAFKA_BROKER_LIST
)
...
@@ -32,6 +42,7 @@ def vest_irrigation(card_id=0, card_type=None, card_user_id=None, create_time=""
...
@@ -32,6 +42,7 @@ def vest_irrigation(card_id=0, card_type=None, card_user_id=None, create_time=""
comment_msg_dict
=
{
comment_msg_dict
=
{
"card_id"
:
card_id
,
"card_id"
:
card_id
,
"card_type"
:
"auto_vest"
,
"card_type"
:
"auto_vest"
,
'card_status'
:
card_type
,
"create_time"
:
create_time
,
"create_time"
:
create_time
,
"content_level"
:
content_level
,
"content_level"
:
content_level
,
"tag_names"
:
tag_names
,
"tag_names"
:
tag_names
,
...
@@ -43,32 +54,35 @@ def vest_irrigation(card_id=0, card_type=None, card_user_id=None, create_time=""
...
@@ -43,32 +54,35 @@ def vest_irrigation(card_id=0, card_type=None, card_user_id=None, create_time=""
logging
.
info
(
"get comment_msg_dict:
%
s"
%
comment_msg_dict
)
logging
.
info
(
"get comment_msg_dict:
%
s"
%
comment_msg_dict
)
producer
.
send
(
topic
,
json
.
dumps
(
comment_msg_dict
)
.
encode
())
producer
.
send
(
topic
,
json
.
dumps
(
comment_msg_dict
)
.
encode
())
follow_msg_dict
=
{
if
card_type
==
'answer'
:
"card_id"
:
card_id
,
follow_msg_dict
=
{
"card_type"
:
"auto_vest"
,
"card_id"
:
card_id
,
"create_time"
:
create_time
,
"card_type"
:
"auto_vest"
,
"content_level"
:
content_level
,
'card_status'
:
card_type
,
"tag_names"
:
tag_names
,
"create_time"
:
create_time
,
"type"
:
"get_write_answer_userinfo"
,
"content_level"
:
content_level
,
"current_push_time"
:
create_time
,
"tag_names"
:
tag_names
,
'action_type'
:
'follow'
,
"type"
:
"get_write_answer_userinfo"
,
'card_user_id'
:
card_user_id
"current_push_time"
:
create_time
,
'action_type'
:
'follow'
,
'card_user_id'
:
card_user_id
}
}
producer
.
send
(
topic
,
json
.
dumps
(
follow_msg_dict
)
.
encode
())
producer
.
send
(
topic
,
json
.
dumps
(
follow_msg_dict
)
.
encode
())
click_msg_dict
=
{
click_msg_dict
=
{
"card_id"
:
card_id
,
"card_id"
:
card_id
,
"card_type"
:
"auto_vest"
,
"card_type"
:
"auto_vest"
,
"create_time"
:
create_time
,
'card_status'
:
card_type
,
"content_level"
:
content_level
,
"create_time"
:
create_time
,
"tag_names"
:
tag_names
,
"content_level"
:
content_level
,
"type"
:
"get_write_answer_userinfo"
,
"tag_names"
:
tag_names
,
"current_push_time"
:
create_time
,
"type"
:
"get_write_answer_userinfo"
,
'action_type'
:
'click'
"current_push_time"
:
create_time
,
'action_type'
:
'click'
}
}
producer
.
send
(
topic
,
json
.
dumps
(
click_msg_dict
)
.
encode
())
producer
.
send
(
topic
,
json
.
dumps
(
click_msg_dict
)
.
encode
())
producer
.
close
()
producer
.
close
()
...
...
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