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
16c3e7df
Commit
16c3e7df
authored
Jan 10, 2020
by
李小芳
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'many_line' into 'master'
add See merge request
!23
parents
05ec711d
1b4c63fc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
56 deletions
+126
-56
click_fun.py
click/views/click_fun.py
+15
-15
comment_fun.py
comment/views/comment_fun.py
+23
-22
follow_fun.py
follow/views/follow_fun.py
+15
-15
consum.py
moment/views/consum.py
+6
-4
process_time.py
moment/views/process_time.py
+67
-0
No files found.
click/views/click_fun.py
View file @
16c3e7df
...
...
@@ -10,21 +10,21 @@ import datetime
def
click
(
card_info
):
try
:
key
=
'have_reply_answer_click:'
+
str
(
card_info
[
'card_id'
])
redis_data
=
redis_client
.
get
(
key
)
if
redis_data
:
datas
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
card_info
[
'current_user_id'
]
in
datas
:
logging
.
info
(
"当前需要去点赞的用户已经存在了:
%
s"
%
card_info
)
return
False
else
:
datas
.
append
(
card_info
[
'current_user_id'
])
redis_client
.
set
(
key
,
json
.
dumps
(
datas
))
else
:
conent
=
[
card_info
[
'current_user_id'
]]
redis_client
.
set
(
key
,
json
.
dumps
(
conent
))
#
key = 'have_reply_answer_click:' + str(card_info['card_id'])
#
redis_data = redis_client.get(key)
#
if redis_data:
#
datas = json.loads(str(redis_data, encoding="utf-8"))
#
if card_info['current_user_id'] in datas:
#
logging.info("当前需要去点赞的用户已经存在了:%s" % card_info)
#
return False
#
#
else:
#
datas.append(card_info['current_user_id'])
#
redis_client.set(key, json.dumps(datas))
#
#
else:
#
conent = [card_info['current_user_id']]
#
redis_client.set(key, json.dumps(conent))
today
=
datetime
.
datetime
.
now
()
str_today
=
str
(
today
.
year
)
+
str
(
today
.
month
)
+
str
(
today
.
day
)
...
...
comment/views/comment_fun.py
View file @
16c3e7df
...
...
@@ -99,28 +99,28 @@ def comment(card_info):
else
:
###判断一下如果评论为空就重新拿一个
if
not
card_info
[
'comment_content'
]:
comment
=
get_vest_userid_and_comment
(
need_comment_num
=
1
,
tag_names
=
card_info
[
'tag_names'
])[
0
]
card_info
[
'comment_content'
]
=
comment
##在这里加一个判断 如果当前的评论的user_id和评论内容已经在这个评论下了就不再下发给同一个回答ID
else
:
key
=
'have_reply_answer_comment:'
+
str
(
card_info
[
'card_id'
])
redis_data
=
redis_client
.
hget
(
key
,
card_info
[
'current_user_id'
])
if
redis_data
:
datas
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
card_info
[
'comment_content'
]
in
datas
:
logging
.
info
(
"当前评论和当前的用户已经存在了:
%
s"
%
card_info
)
return
False
else
:
datas
.
append
(
card_info
[
'comment_content'
])
redis_client
.
hset
(
key
,
card_info
[
'current_user_id'
],
json
.
dumps
(
datas
))
else
:
conent
=
[
card_info
[
'comment_content'
]]
redis_client
.
hset
(
key
,
card_info
[
'current_user_id'
],
json
.
dumps
(
conent
))
#
#
##判断一下如果评论为空就重新拿一个
#
if not card_info['comment_content']:
#
comment = get_vest_userid_and_comment(need_comment_num=1, tag_names=card_info['tag_names'])[0]
#
card_info['comment_content'] = comment
#
#
#
#在这里加一个判断 如果当前的评论的user_id和评论内容已经在这个评论下了就不再下发给同一个回答ID
#
else:
#
key = 'have_reply_answer_comment:' + str(card_info['card_id'])
#
redis_data = redis_client.hget(key, card_info['current_user_id'])
#
if redis_data:
#
datas = json.loads(str(redis_data, encoding="utf-8"))
#
if card_info['comment_content'] in datas:
#
logging.info("当前评论和当前的用户已经存在了:%s" % card_info)
#
return False
#
#
else:
#
datas.append(card_info['comment_content'])
#
redis_client.hset(key, card_info['current_user_id'], json.dumps(datas))
#
#
else:
#
conent = [card_info['comment_content']]
#
redis_client.hset(key, card_info['current_user_id'], json.dumps(conent))
####当天下发的次数存起来,每次下发判断已经下发了多少个 如果当前下发相等不再下发
today
=
datetime
.
datetime
.
now
()
...
...
@@ -145,6 +145,7 @@ def comment(card_info):
else
:
redis_data
=
{
"comment_have_pust_num"
:
card_info
[
'have_pust_num'
],
"comment_need_pust_num"
:
card_info
[
'need_pust_num'
]}
redis_client
.
hset
(
key
,
str_today
,
json
.
dumps
(
redis_data
))
logging
.
info
(
"get action:comment,card_id:
%
s,redis_data:
%
s"
%
(
card_info
[
'card_id'
],
redis_data
))
...
...
follow/views/follow_fun.py
View file @
16c3e7df
...
...
@@ -10,21 +10,21 @@ import datetime
def
follow
(
card_info
):
try
:
key
=
'have_reply_answer_follow:'
+
str
(
card_info
[
'card_id'
])
redis_data
=
redis_client
.
get
(
key
)
if
redis_data
:
datas
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
card_info
[
'current_user_id'
]
in
datas
:
logging
.
info
(
"当前需要去关注的用户已经存在了:
%
s"
%
card_info
)
return
False
else
:
datas
.
append
(
card_info
[
'current_user_id'
])
redis_client
.
set
(
key
,
json
.
dumps
(
datas
))
else
:
conent
=
[
card_info
[
'current_user_id'
]]
redis_client
.
set
(
key
,
json
.
dumps
(
conent
))
#
key = 'have_reply_answer_follow:' + str(card_info['card_id'])
#
redis_data = redis_client.get(key)
#
if redis_data:
#
datas = json.loads(str(redis_data, encoding="utf-8"))
#
if card_info['current_user_id'] in datas:
#
logging.info("当前需要去关注的用户已经存在了:%s" % card_info)
#
return False
#
#
else:
#
datas.append(card_info['current_user_id'])
#
redis_client.set(key, json.dumps(datas))
#
#
else:
#
conent = [card_info['current_user_id']]
#
redis_client.set(key, json.dumps(conent))
today
=
datetime
.
datetime
.
now
()
str_today
=
str
(
today
.
year
)
+
str
(
today
.
month
)
+
str
(
today
.
day
)
...
...
moment/views/consum.py
View file @
16c3e7df
...
...
@@ -19,7 +19,7 @@ from comment.views.comment_fun import comment
from
follow.views.follow_fun
import
follow
from
libs.cache
import
redis_client
from
kafka.structs
import
TopicPartition
from
moment.views.process_time
import
judge_offset_partition_have_consum
from
moment.views.process_time
import
judge_offset_partition_have_consum
,
judge_data_have_in_redis
def
kafka_consum
(
topic_name
=
None
):
...
...
@@ -35,7 +35,7 @@ def kafka_consum(topic_name=None):
# consumser_obj.seek(partition=TopicPartition(topic_name,int(partition_id.decode())),offset=int(topic_partition_info[partition_id]))
while
True
:
begin
=
time
.
time
()
msg_dict
=
consumser_obj
.
poll
(
timeout_ms
=
100
,
max_records
=
3
0
)
msg_dict
=
consumser_obj
.
poll
(
timeout_ms
=
100
,
max_records
=
5
0
)
for
msg_value
in
msg_dict
.
values
():
for
msg
in
msg_value
:
card_info
=
json
.
loads
(
str
(
msg
.
value
,
encoding
=
"utf8"
))
...
...
@@ -43,7 +43,9 @@ def kafka_consum(topic_name=None):
###在这里去判断一下当前的partition和offset是否已经消费过了 如果已经消费了需要直接去掉数据
# bol_consum = judge_offset_partition_have_consum(card_info=card_info, offset=msg.offset,
# partition=msg.partition)
bol_consum
=
True
##在这里先判断当前的数据是否已经存在,存在的话直接PaaS,不存在的话再做下边的处理
bol_consum
=
judge_data_have_in_redis
(
card_info
)
# bol_consum = True
if
bol_consum
:
logging
.
info
(
"消费到新数据了[
%
s,
%
s,
%
s,
%
s],get card_info:
%
s"
%
(
str
(
msg
.
topic
),
str
(
msg
.
partition
),
str
(
msg
.
offset
),
str
(
msg
.
key
),
card_info
))
...
...
@@ -160,7 +162,7 @@ def kafka_consum(topic_name=None):
str
(
msg
.
topic
),
str
(
msg
.
partition
),
str
(
msg
.
offset
),
str
(
msg
.
key
)))
save_data_to_kafka
(
card_info
)
else
:
logging
.
info
(
"此条数据已经
消费过
了:
%
s"
%
card_info
)
logging
.
info
(
"此条数据已经
被paas
了:
%
s"
%
card_info
)
logging
.
info
(
"消费处理耗时:
%
f"
%
(
time
.
time
()
-
begin
))
except
:
consumser_obj
.
close
()
...
...
moment/views/process_time.py
View file @
16c3e7df
...
...
@@ -359,6 +359,73 @@ def judge_offset_partition_have_consum(card_info=None, offset=0, partition=0):
return
False
def
judge_data_have_in_redis
(
card_info
=
None
):
try
:
if
card_info
[
'card_status'
]
==
'comment'
:
##在这里加一个判断 如果当前的评论的user_id和评论内容已经在这个评论下了就不再下发给同一个回答ID
key
=
'have_reply_answer_comment:'
+
str
(
card_info
[
'card_id'
])
redis_data
=
redis_client
.
hget
(
key
,
card_info
[
'current_user_id'
])
if
redis_data
:
datas
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
card_info
[
'comment_content'
]
in
datas
:
logging
.
info
(
"当前评论和当前的用户已经存在了:
%
s"
%
card_info
)
return
False
else
:
datas
.
append
(
card_info
[
'comment_content'
])
redis_client
.
hset
(
key
,
card_info
[
'current_user_id'
],
json
.
dumps
(
datas
))
return
True
else
:
conent
=
[
card_info
[
'comment_content'
]]
redis_client
.
hset
(
key
,
card_info
[
'current_user_id'
],
json
.
dumps
(
conent
))
return
True
elif
card_info
[
'card_status'
]
==
'follow'
:
key
=
'have_reply_answer_follow:'
+
str
(
card_info
[
'card_id'
])
redis_data
=
redis_client
.
get
(
key
)
if
redis_data
:
datas
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
card_info
[
'current_user_id'
]
in
datas
:
logging
.
info
(
"当前需要去关注的用户已经存在了:
%
s"
%
card_info
)
return
False
else
:
datas
.
append
(
card_info
[
'current_user_id'
])
redis_client
.
set
(
key
,
json
.
dumps
(
datas
))
return
True
else
:
conent
=
[
card_info
[
'current_user_id'
]]
redis_client
.
set
(
key
,
json
.
dumps
(
conent
))
return
True
else
:
key
=
'have_reply_answer_click:'
+
str
(
card_info
[
'card_id'
])
redis_data
=
redis_client
.
get
(
key
)
if
redis_data
:
datas
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
card_info
[
'current_user_id'
]
in
datas
:
logging
.
info
(
"当前需要去点赞的用户已经存在了:
%
s"
%
card_info
)
return
False
else
:
datas
.
append
(
card_info
[
'current_user_id'
])
redis_client
.
set
(
key
,
json
.
dumps
(
datas
))
return
True
else
:
conent
=
[
card_info
[
'current_user_id'
]]
redis_client
.
set
(
key
,
json
.
dumps
(
conent
))
return
True
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
def
get_current_card_content_level
(
card_info
=
[]):
try
:
# 判断当前卡片的等级
...
...
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