Commit 75e57c50 authored by lixiaofang's avatar lixiaofang

新增类型

parent 60d1bb37
......@@ -5,23 +5,31 @@ import logging
from libs.cache import redis_client
import json
from moment.views.send_email import send_email_tome
import datetime
def click(card_info):
try:
key = "auto_vest_one_user_action:" + str(card_info['card_id'])
redis_data = redis_client.get(key)
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("click")) + 1
redis_data['click'] = click_num
redis_client.set(key, json.dumps(redis_data))
redis_client.hset(key, str_today, json.dumps(redis_data))
else:
##代表还没有存储或者是已经过去一天了 需要清掉数据 从新的一天开始
redis_client.delete(key)
redis_data = {"click": 1, "follow": 0, "comment": 0}
redis_client.set(key, json.dumps(redis_data))
redis_client.expire(key, time=24 * 60 * 60)
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"]
if click_num > 10:
return True
# send_email_tome(str(redis_data) + str(card_info))
......@@ -29,9 +37,6 @@ def click(card_info):
rpc_invoker = get_rpc_invoker()
rpc_invoker['qa/irrigation/create_answer_vote'](user_id=card_info['current_user_id'],
answer_id=card_info['card_id']).unwrap()
# values = list(redis_data.values())
# s = [True for i in values if i > 10]
return True
except:
logging_exception()
......
......@@ -5,6 +5,7 @@ import logging
from libs.cache import redis_client
import json
from moment.views.send_email import send_email_tome
import datetime
def comment(card_info):
......@@ -15,22 +16,27 @@ def comment(card_info):
"""
try:
if card_info['card_status'] == 'tractate':
key = "tractate_auto_vest_one_user_action:" + str(card_info['card_id'])
redis_data = redis_client.get(key)
today = datetime.datetime.now()
str_today = str(today.year) + str(today.month) + str(today.day)
key = "auto_vest_one_user_action_tractate:" + 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.set(key, json.dumps(redis_data))
redis_client.hset(key, str_today, json.dumps(redis_data))
else:
##代表还没有存储或者是已经过去一天了 需要清掉数据 从新的一天开始
redis_client.delete(key)
redis_data = {"comment": 1}
redis_client.set(key, json.dumps(redis_data))
redis_client.expire(key, time=24 * 60 * 60)
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"]
####在这里做判断 一天不能超过20个 如果超过二十个不下发 不超过二十个下发对应的灌水功能
if comment_num > 20:
if comment_num > 12:
return True
# send_email_tome(str(redis_data) + str(card_info))
else:
......@@ -40,22 +46,26 @@ def comment(card_info):
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)
today = datetime.datetime.now()
str_today = str(today.year) + str(today.month) + str(today.day)
key = "auto_vest_one_user_action_diary:" + 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.set(key, json.dumps(redis_data))
redis_client.hset(key, str_today, json.dumps(redis_data))
else:
redis_client.delete(key)
redis_data = {"comment": 1}
redis_client.set(key, json.dumps(redis_data))
redis_client.expire(key, time=24 * 60 * 60)
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"]
####在这里做判断 一天不能超过20个 如果超过二十个不下发 不超过二十个下发对应的灌水功能
if comment_num > 20:
if comment_num > 12:
return True
# send_email_tome(str(redis_data) + str(card_info))
else:
......@@ -65,22 +75,27 @@ def comment(card_info):
content=card_info['comment_content']).unwrap()
else:
key = "auto_vest_one_user_action:" + str(card_info['card_id'])
redis_data = redis_client.get(key)
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.set(key, json.dumps(redis_data))
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.set(key, json.dumps(redis_data))
redis_client.expire(key, time=24 * 60 * 60)
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"]
####在这里做判断 一天不能超过20个 如果超过二十个不下发 不超过二十个下发对应的灌水功能
if comment_num > 20:
if comment_num > 12:
return True
# send_email_tome(str(redis_data) + str(card_info))
else:
......
......@@ -5,23 +5,26 @@ import logging
from libs.cache import redis_client
import json
from moment.views.send_email import send_email_tome
import datetime
def follow(card_info):
try:
key = "auto_vest_one_user_action:" + str(card_info['card_id'])
redis_data = redis_client.get(key)
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("follow")) + 1
redis_data['follow'] = click_num
redis_client.set(key, json.dumps(redis_data))
redis_client.hset(key, str_today, json.dumps(redis_data))
else:
redis_client.delete(key)
redis_data = {"click": 0, "follow": 1, "comment": 0}
redis_client.set(key, json.dumps(redis_data))
redis_client.expire(key, time=24 * 60 * 60)
logging.info("get action:follow,card_id:%s,redis_data:%s" % (card_info['card_id'], redis_data))
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"]
if follow_num > 10:
......@@ -31,8 +34,6 @@ def follow(card_info):
rpc_invoker = get_rpc_invoker()
rpc_invoker['api/irrigation/user_add_follow'](follow_user_id=card_info['current_user_id'],
followed_user_id=card_info['card_user_id']).unwrap()
# values = list(redis_data.values())
# s = [True for i in values if i > 10]
return True
except:
......
......@@ -17,9 +17,15 @@ from bs4 import BeautifulSoup
logger = logging.getLogger(__name__)
producer = KafkaProducer(bootstrap_servers=settings.KAFKA_BROKER_LIST)
db_zhengxing_eagle = pymysql.connect(host=settings.HOST, port=settings.PORT, user=settings.USER,
password=settings.PASSWORD,
db=settings.NAME)
db_mimas_eagle = pymysql.connect(host=settings.HOST, port=settings.PORT, user=settings.USER,
password=settings.PASSWORD,
db=settings.NAME)
mimas_cursor = db_mimas_eagle.cursor()
db_zhengxing_eagle = pymysql.connect(host=settings.HOST1, port=settings.PORT, user=settings.USER1,
password=settings.PASSWORD1,
db=settings.NAME1)
zhengxing_cursor = db_zhengxing_eagle.cursor()
......@@ -154,7 +160,7 @@ def get_content_time_by_create_time(create_time="", content_level=0, action_type
repeat_time=0):
try:
###在这个地方需要重新判断一下星级
# content_level = get_current_card_content_level(card_info)
card_info['content_level'] = get_current_card_content_level(card_info)
##
card_info['type'] = 'have_get_push_time'
card_info['have_comment_number'] = 0
......@@ -201,6 +207,9 @@ def get_content_time_by_create_time(create_time="", content_level=0, action_type
def get_click_follow_time_by_create_time(create_time="", content_level=0, action_type=None, after_day=False,
card_info=None, repeat_time=0):
try:
######在这个地方需要重新判断一下星级
card_info['content_level'] = get_current_card_content_level(card_info)
####
card_info['have_click_number'] = 0
card_info['have_follow_number'] = 0
now = datetime.datetime.now()
......@@ -346,23 +355,24 @@ def judge_offset_partition_have_consum(offset=0, partition=0):
def get_current_card_content_level(card_info=[]):
try:
# 先根据card_id回去内容提取关键字
# 判断当前卡片的等级
if card_info['card_status'] == 'answer':
sql = 'select level from api_answer where id = %s ' % (card_info['card_id'])
mimas_cursor.execute(sql)
data = list(mimas_cursor.fetchall())
sql = 'select content from api_answer where id = %s ' % (card_info['card_id'])
# zhengxing_cursor.execute(sql)
# data = list(zhengxing_cursor.fetchall())
# logging.info("get data:%s" % data)
# zhengxing_cursor.close()
# if len(data) > 0:
# soup = BeautifulSoup(data[0][0], 'html.parser')
# contents = soup.text
#
# ck = GetContentKeyWords()
# keywords = ck.get_keywords(contents, len(ck.tag_list))
# if keywords:
# tag_names.append(keywords)
#
# return tag_names
if card_info['card_status'] == 'tractate':
sql = 'select content_level from api_tractate where id = %s ' % (card_info['card_id'])
mimas_cursor.execute(sql)
data = list(mimas_cursor.fetchall())
if card_info['card_status'] == 'diary':
sql = 'select content_level from api_diary where id = %s ' % (card_info['card_id'])
zhengxing_cursor.execute(sql)
data = list(zhengxing_cursor.fetchall())
if len(data) > 0:
return int(data[0][0])
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
......@@ -20,6 +20,12 @@ PASSWORD = 'Gengmei1'
HOST = 'bj-cdb-6slgqwlc.sql.tencentcdb.com'
PORT = 62120
ENGINE1 = 'django.db.backends.mysql', # 设置为mysql数据库
NAME1 = 'zhengxing_test'
USER1 = 'work'
PASSWORD1 = 'Gengmei1'
HOST1 = 'bj-cdb-6slgqwlc.sql.tencentcdb.com'
OPTIONS = {
"init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4", # 为了支持emoji表情
......
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