Commit e3560c64 authored by lixiaofang's avatar lixiaofang

add

parents 237e8e1c 90ff242b
......@@ -90,7 +90,6 @@ def auto_click_user(card_info, after_day=False):
card_info["have_pust_num"] = card_info["have_pust_num"] + 1
save_data_to_kafka(card_info) # 存储数据
logging.info("get--------click--------------card_info:%s" % card_info)
except:
logging_exception()
......
......@@ -3,54 +3,71 @@ import traceback
from libs.error import logging_exception
import logging
from libs.cache import redis_client
import json
import json, time
from moment.views.send_email import send_email_tome
from moment.views.process_time import get_vest_userid
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:
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)
key = "auto_vest_one_user_action_answer:" + str(card_info['card_id'])
key = "auto_vest_action_click_answer:" + str(card_info['card_id'])
redis_data = redis_client.hget(key, str_today)
if redis_data:
redis_data = json.loads(str(redis_data, encoding="utf8"))
click_num = int(redis_data.get("click")) + 1
redis_data['click'] = click_num
redis_client.hset(key, str_today, json.dumps(redis_data))
have_pust_num = int(redis_data.get('click_have_pust_num', card_info['have_pust_num']))
need_pust_num = int(redis_data.get('click_need_pust_num', card_info['need_pust_num']))
if have_pust_num > need_pust_num:
return True
else:
redis_data['click_have_pust_num'] = have_pust_num + 1
redis_client.hset(key, str_today, json.dumps(redis_data))
else:
##代表还没有存储或者是已经过去一天了 需要清掉数据 从新的一天开始
redis_client.delete(key)
redis_data = {"click": 1, "follow": 0, "comment": 0}
redis_data = {"click_have_pust_num": card_info['have_pust_num'],
"click_need_pust_num": card_info['need_pust_num']}
redis_client.hset(key, str_today, json.dumps(redis_data))
logging.info("get action:click,card_id:%s,redis_data:%s" % (card_info['card_id'], redis_data))
click_num = redis_data["click"]
rpc_invoker = get_rpc_invoker()
try:
begin = time.time()
current_user_id = get_vest_userid(need_comment_num=1)[0]
status = rpc_invoker['qa/irrigation/create_answer_vote'](user_id=current_user_id,
answer_id=card_info['card_id']).unwrap()
logging.info('get_create_answer_vote_status:%s,card_id:%s,create_time:%s,耗时:%s' % (
status, card_info['card_id'], card_info['create_time'], time.time() - begin))
error = status.get('error', 1)
if error == 0:
return True
else:
send_email_tome(str(card_info) + str(status))
return False
except:
logging_exception()
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
if click_num > 12:
logging.info("今天已经消费到最大次数了,不能再消费")
return True, False
else:
rpc_invoker = get_rpc_invoker()
try:
status = rpc_invoker['qa/irrigation/create_answer_vote'](user_id=card_info['current_user_id'],
answer_id=card_info['card_id']).unwrap()
logging.info("get_card_info:%s,create_answer_vote:%s" % (card_info, status))
error = status.get('error', 1)
if error == 0:
return True, True
else:
send_email_tome(str(card_info) + str(status))
return False, True
except:
logging_exception()
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False, True
except:
logging_exception()
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False, False
return False
......@@ -50,6 +50,7 @@ def auto_comment_user(card_info, after_day=False):
content_level = card_info["content_level"]
card_info["action_type"] = "comment"
tag_names = card_info['tag_names']
tagv3_names = card_info['tagv3_names']
# 当满足这些条件的时候 代表已经完成了下发的所有的时间或者还没有下发过时间 需要给予新的时间
if ("all_follow_id" in card_info and "all_push_time" in card_info and len(
......@@ -71,8 +72,7 @@ def auto_comment_user(card_info, after_day=False):
if len(get_time) > 0 and time_region != 3:
###拿到下发时间后根据下发的时间个数去拿对应个数的马甲账号
all_content = get_vest_userid_and_comment(need_comment_num=len(get_time),
tag_names=tag_names,
card_id=card_info['card_id'])
tag_names=tag_names, tagv3_names=tagv3_names)
userids = get_vest_userid(need_comment_num=len(get_time))
for i in range(0, len(userids)):
......@@ -93,7 +93,6 @@ def auto_comment_user(card_info, after_day=False):
break
repeat_time += 1
logging.info("get comment_have_get_after__time:%s" % card_info)
else: # 代表还有push好的时间没有下发完成 需要继续使用这些
current_user_id = card_info["current_user_id"]
card_info["all_follow_id"].remove(current_user_id)
......@@ -114,7 +113,6 @@ def auto_comment_user(card_info, after_day=False):
card_info['current_push_time'] = card_info['all_push_time'][0]
save_data_to_kafka(card_info) # 存储数据
logging.info("get-------comment---------------card_info:%s" % card_info)
except:
logging_exception()
......
......@@ -3,10 +3,10 @@ import traceback
from libs.error import logging_exception
import logging
from libs.cache import redis_client
import json
import json, time
from moment.views.send_email import send_email_tome
import datetime
from moment.views.process_time import get_vest_userid_and_comment
from moment.views.process_time import get_vest_userid_and_comment, get_vest_userid
def comment(card_info):
......@@ -33,7 +33,6 @@ def comment(card_info):
redis_data = {"comment": 1}
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))
comment_num = redis_data["comment"]
if comment_num > 12:
......@@ -45,7 +44,6 @@ def comment(card_info):
answer_id=card_info['card_id'],
content=card_info[
'comment_content']).unwrap()
logging.info("get_card_info:%s,have_answer_reply:%s" % (card_info, status))
error = status.get('error', 1)
if error == 0 and comment_num <= 11:
return True, True
......@@ -74,7 +72,6 @@ def comment(card_info):
redis_data = {"comment": 1}
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))
comment_num = redis_data["comment"]
if comment_num > 12:
......@@ -86,7 +83,6 @@ def comment(card_info):
answer_id=card_info['card_id'],
content=card_info[
'comment_content']).unwrap()
logging.info("get_card_info:%s,have_answer_reply:%s" % (card_info, status))
error = status.get('error', 1)
if error == 0:
return True
......@@ -98,27 +94,11 @@ def comment(card_info):
return False
else:
today = datetime.datetime.now()
str_today = str(today.year) + str(today.month) + str(today.day)
key = "auto_vest_one_user_action_answer:" + str(card_info['card_id'])
redis_data = redis_client.hget(key, str_today)
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.hset(key, str_today, json.dumps(redis_data))
else:
redis_client.delete(key)
redis_data = {"click": 0, "follow": 0, "comment": 1}
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))
comment_num = redis_data["comment"]
###判断一下如果评论为空就重新拿一个
if not card_info['comment_content']:
comment = get_vest_userid_and_comment(need_comment_num=1, tag_names=card_info['tag_names'])[0]
comment = get_vest_userid_and_comment(need_comment_num=1, tag_names=card_info['tag_names'],
tagv3_names=card_info['tagv3_names'])[0]
card_info['comment_content'] = comment
##在这里加一个判断 如果当前的评论的user_id和评论内容已经在这个评论下了就不再下发给同一个回答ID
......@@ -126,10 +106,9 @@ def comment(card_info):
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(redis_data, encoding="utf-8")
datas = json.loads(str(redis_data, encoding="utf-8"))
if card_info['comment_content'] in datas:
logging.info("当前评论和当前的用户已经存在了")
pass
return False
else:
datas.append(card_info['comment_content'])
redis_client.hset(key, card_info['current_user_id'], json.dumps(datas))
......@@ -137,28 +116,53 @@ def comment(card_info):
conent = [card_info['comment_content']]
redis_client.hset(key, card_info['current_user_id'], json.dumps(conent))
if comment_num > 12:
logging.info("今天已经消费到最大次数了,不能再消费")
return True, False
###当天下发的次数存起来,每次下发判断已经下发了多少个 如果当前下发相等不再下发
today = datetime.datetime.now()
str_today = str(today.year) + str(today.month) + str(today.day)
key = "auto_vest_action_comment_answer:" + str(card_info['card_id'])
redis_data = redis_client.hget(key, str_today)
if redis_data:
redis_data = json.loads(str(redis_data, encoding="utf8"))
have_pust_num = int(redis_data.get('comment_have_pust_num', card_info['have_pust_num']))
need_pust_num = int(redis_data.get('comment_need_pust_num', card_info['need_pust_num']))
if have_pust_num > need_pust_num:
return True
else:
redis_data['comment_have_pust_num'] = have_pust_num + 1
redis_client.hset(key, str_today, json.dumps(redis_data))
else:
rpc_invoker = get_rpc_invoker()
try:
status = 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()
logging.info("get_card_info:%s,have_answer_reply:%s" % (card_info, status))
error = status.get('error', 1)
if error == 0:
return True, True
else:
send_email_tome(str(card_info) + str(status))
return False, True
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False, True
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))
rpc_invoker = get_rpc_invoker()
try:
begin = time.time()
current_user_id = get_vest_userid(need_comment_num=1)[0]
status = rpc_invoker['qa/irrigation/create_answer_reply'](user_id=current_user_id,
answer_id=card_info['card_id'],
content=card_info[
'comment_content']).unwrap()
logging.info('get_create_answer_reply_status:%s,card_id:%s,create_time:%s,耗时:%s' % (
status, card_info['card_id'], card_info['create_time'], time.time() - begin))
error = status.get('error', 1)
if error == 0:
return True
else:
send_email_tome(str(card_info) + str(status))
return False
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
except:
logging_exception()
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False, False
return False
......@@ -93,7 +93,6 @@ def auto_follow_user(card_info, after_day=False):
card_info['current_push_time'] = card_info['all_push_time'][0]
save_data_to_kafka(card_info) # 存储数据
logging.info("get-------follow---------------card_info:%s" % card_info)
except:
logging_exception()
......
......@@ -3,52 +3,73 @@ import traceback
from libs.error import logging_exception
import logging
from libs.cache import redis_client
import json
import json, time
from moment.views.send_email import send_email_tome
from moment.views.process_time import get_vest_userid
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:
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)
key = "auto_vest_one_user_action_answer:" + str(card_info['card_id'])
key = "auto_vest_action_follow_answer:" + str(card_info['card_id'])
redis_data = redis_client.hget(key, str_today)
if redis_data:
redis_data = json.loads(str(redis_data, encoding="utf8"))
click_num = int(redis_data.get("follow")) + 1
redis_data['follow'] = click_num
redis_client.hset(key, str_today, json.dumps(redis_data))
have_pust_num = int(redis_data.get('follow_have_pust_num', card_info['have_pust_num']))
need_pust_num = int(redis_data.get('follow_need_pust_num', card_info['need_pust_num']))
if have_pust_num > need_pust_num:
return True
else:
redis_data['follow_have_pust_num'] = have_pust_num + 1
redis_client.hset(key, str_today, json.dumps(redis_data))
else:
redis_client.delete(key)
redis_data = {"click": 0, "follow": 1, "comment": 0}
redis_data = {"follow_have_pust_num": card_info['have_pust_num'],
"follow_need_pust_num": card_info['need_pust_num']}
redis_client.hset(key, str_today, json.dumps(redis_data))
logging.info("get action:follow,card_id:%s,redis_data:%s" % (card_info['card_id'], redis_data))
follow_num = redis_data["follow"]
rpc_invoker = get_rpc_invoker()
try:
begin = time.time()
current_user_id = get_vest_userid(need_comment_num=1)[0]
status = rpc_invoker['api/irrigation/user_add_follow'](follow_user_id=current_user_id,
followed_user_id=card_info[
'card_user_id']).unwrap()
logging.info(
'get_user_add_follow_status:%s,card_id:%s,create_time:%s,耗时:%s' % (
status, card_info['card_id'], card_info['create_time'], time.time() - begin))
if follow_num > 11:
logging.info("今天已经消费到最大次数了,不能再消费")
return True, False
error = status.get('error', 1)
if error == 0:
return True
else:
send_email_tome(str(card_info) + str(status))
return False
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
else:
rpc_invoker = get_rpc_invoker()
try:
status = rpc_invoker['api/irrigation/user_add_follow'](follow_user_id=card_info['current_user_id'],
followed_user_id=card_info[
'card_user_id']).unwrap()
logging.info("get_card_info:%s,user_add_follow:%s" % (card_info, status))
error = status.get('error', 1)
if error == 0:
return True, True
else:
send_email_tome(str(card_info) + str(status))
return False, True
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False, True
except:
logging_exception()
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False, False
return False
This diff is collapsed.
This diff is collapsed.
......@@ -13,7 +13,8 @@ from libs.error import logging_exception
@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=[],
tagv3_names=[]):
"""
在这里把后端传的数据存进卡夫卡 日记和帖子只需要发评论不需要点赞和关注
:param card_id:
......@@ -27,16 +28,15 @@ def vest_irrigation(card_id=0, card_type=None, card_user_id=None, create_time=""
try:
producer = KafkaProducer(bootstrap_servers=settings.KAFKA_BROKER_LIST)
logging.info("新数据进来了:%s" % card_id)
topic = settings.KAFKA_TOPIC_NAME
tag_list = ["瘦脸针kyc", "双眼皮kyc", "水光针kyc", "玻尿酸kyc", "吸脂kyc", "祛痘kyc", "鼻综合kyc", "光子嫩肤kyc", "没有想法kyc",
"牙齿kyc", "抗衰紧致kyc", "胸部kyc", "果酸换肤kyc", "祛斑kyc", "美白针kyc", "瘦腿针kyc"]
flag = False
if len(tag_names) > 0:
for i in tag_names:
if i in tag_list:
flag = True
flag = True
# tag_list = ["瘦脸针kyc", "双眼皮kyc", "水光针kyc", "玻尿酸kyc", "吸脂kyc", "祛痘kyc", "鼻综合kyc", "光子嫩肤kyc", "没有想法kyc",
# "牙齿kyc", "抗衰紧致kyc", "胸部kyc", "果酸换肤kyc", "祛斑kyc", "美白针kyc", "瘦腿针kyc"]
# flag = False
# if len(tag_names) > 0:
# for i in tag_names:
# if i in tag_list:
# flag = True
if flag == True:
comment_msg_dict = {
......@@ -48,10 +48,10 @@ def vest_irrigation(card_id=0, card_type=None, card_user_id=None, create_time=""
"tag_names": tag_names,
"type": "get_write_answer_userinfo",
"current_push_time": create_time,
'action_type': 'comment'
'action_type': 'comment',
"tagv3_names": tagv3_names
}
logging.info("get comment_msg_dict:%s" % comment_msg_dict)
producer.send(topic, json.dumps(comment_msg_dict).encode())
if card_type == 'answer':
......@@ -65,7 +65,8 @@ def vest_irrigation(card_id=0, card_type=None, card_user_id=None, create_time=""
"type": "get_write_answer_userinfo",
"current_push_time": create_time,
'action_type': 'follow',
'card_user_id': card_user_id
'card_user_id': card_user_id,
"tagv3_names": tagv3_names
}
producer.send(topic, json.dumps(follow_msg_dict).encode())
......@@ -79,7 +80,8 @@ def vest_irrigation(card_id=0, card_type=None, card_user_id=None, create_time=""
"tag_names": tag_names,
"type": "get_write_answer_userinfo",
"current_push_time": create_time,
'action_type': 'click'
'action_type': 'click',
"tagv3_names": tagv3_names
}
producer.send(topic, json.dumps(click_msg_dict).encode())
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment