Commit 5a16a12d authored by 谢祁峰's avatar 谢祁峰

fix

parents 81fbb0fb 63a42a94
......@@ -20,6 +20,7 @@ RUN apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32 \
&& apt-get -y update && apt-get -y install mysql-client libmysqlclient-dev \
&& apt-get clean \
&& apt-get autoclean \
&& apt-get -y install vim \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
......
crontab:
cp crontab.py /data/log/physical/app/crontab.py && python /data/log/physical/app/crontab.py && python /data/log/physical/app/crontabs.py
celery:
celery -A physical worker -c 1 -Q vest -l debug
......@@ -55,10 +55,8 @@ celery -A physical beat
### physical策略端脚本
在Alp-Test-Cos-test001服务器上,通过crontab -l查看
<<<<<<< README.md
更新脚本
```bash
make crontab
```
......@@ -15,21 +15,17 @@ ontime_list = [
"30 10 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_urge2",
"0 10 * * 3 source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_lunch_app",
"30 10 * * 3 source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_lunch_app2",
"*/5 * * * 1 source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_follow_per_5m_by_followed",
# "*/5 * * * 1 source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_follow_per_5m_by_followed",
"1 */2 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_follow_per_2h_by_post_and_regist",
"0 9 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m get_login_session",
"0 0 * * 3 source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m get_user_id",
# "0 14,18,22 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m principal_online_comment1",
"25 */2 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_reply_per_2h_to_topic"
]
random_time_list = [
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_click_per_1d_by_post",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_follow_per_1d_by_regist",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_follow_per_1d_by_post",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_reply_per_1d_to_pictorial",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_reply_per_1d_to_topic"
"25 */2 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_reply_per_2h_to_topic",
"0 9 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_click_per_1d_by_post",
"1 9 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_follow_per_1d_by_regist",
"2 9 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_follow_per_1d_by_post",
"3 9 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_reply_per_1d_to_pictorial",
"4 9 * * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m auto_reply_per_1d_to_topic"
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m answer_reply1",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m answer_reply2",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m answer_reply3",
......@@ -48,16 +44,6 @@ random_time_list = [
]
###随机生成10-23的一个数字 代表小时
ss1 = random.choices(range(10, 23), k=100)
###随机生成1-60的一个数字 表示分钟
ss2 = random.choices(range(1, 50), k=100)
for i in range(len(random_time_list)):
ontime_list.append(str(ss2[i]) + " " + str(ss1[i]) + " " + str(random_time_list[i]))
data = open("/data/log/physical/app/conf.txt", "w")
# data = open("abc.txt", "w")
......
import pytz
import random
from datetime import datetime, timedelta
NOW = datetime.now()
def tzlc(dt, truncate_to_sec=True):
if dt is None:
return None
if truncate_to_sec:
dt = dt.replace(microsecond=0)
return pytz.timezone('Asia/Shanghai').localize(dt)
def eta_2_push_time(eta):
if eta:
eta = datetime.strptime(eta, '%Y-%m-%d %H:%M:%S')
eta = tzlc(eta)
return int((eta - datetime.fromtimestamp(0, pytz.timezone("UTC"))).total_seconds())
else:
push_time = None
return push_time
def get_rand_time(hourlow=0, hourup=13, minutelow=0, minuteup=60):
hours = random.randint(hourlow, hourup)
minutes = random.randint(minutelow, minuteup)
# todo redis会自动给加8个小时,所以这边先写死减少8小时
now_time = NOW + timedelta(hours=hours, minutes=minutes) - timedelta(hours=8)
time = eta_2_push_time(now_time.strftime("%Y-%m-%d %H:%M:%S"))
print(datetime.fromtimestamp(time))
return datetime.fromtimestamp(time)
if __name__ == '__main__':
get_rand_time()
......@@ -304,7 +304,7 @@ class CollectData(object):
logging.info("positive tag_list,device_id:%s,topic_id:%s,tag_list:%s" % (
str(device_id), str(topic_id), str(click_topic_tag_list)))
# 更新不同策略的lin标签参数信息
#点击信息流卡片(问题卡片和回答卡片)对应的标签权重为1
# 点击信息流卡片(问题卡片和回答卡片)对应的标签权重为1
for tag_id in click_topic_tag_list:
self.update_user_linucb_tag_info(reward, device_id, tag_id, user_feature,
self.linucb_matrix_redis_prefix)
......@@ -539,7 +539,6 @@ class CollectData(object):
reward = 1 if is_click or is_vote else 0
# 移植老用户的lin信息到ctr特征策略
self.transfer_old_info2ctr_feature_key(device_id)
for i in range(5):
for tag_id in tag_query_results_multi:
self.update_user_linucb_tag_info(reward, device_id, tag_id,
......@@ -566,53 +565,87 @@ class CollectData(object):
logging.info("skin_check topic type:%s, device_id:%s, tag_query_results:%s" %
(str(data['SYS']['action']), str(device_id),
str(tag_query_results_multi)))
# 品牌问卷进linucb
elif 'SYS' in data and 'APP' in data and 'action' in data['SYS'] and data['SYS'][
'action'] == "venus/community/survey_question/submit":
device_id = data['SYS']['cl_id']
tagid_list = list(data['APP'].get('answer_tag', []))
user_id = data['SYS'].get('user_id', None)
logging.info("survey_question type:%s, device_id:%s, answer_tag:%s" %
(str(data['SYS']['action']), str(device_id), str(tagid_list)))
if len(tagid_list) > 0:
tag_query_results = list(Tag.objects.using(settings.SLAVE1_DB_NAME).filter(
id__in=tagid_list, is_online=True, is_deleted=False,
is_category=False).values_list("id", flat=True))
tag_query_results_multi = [i for i in tagid_list if i in tag_query_results]
is_click = 1
is_vote = 0
# 品牌问卷进linucb
elif 'SYS' in data and 'APP' in data and 'action' in data['SYS'] and data['SYS'][
'action'] == "venus/community/survey_question/submit":
device_id = data['SYS']['cl_id']
tagid_list = list(data['APP'].get('answer_tag', []))
user_id = data['SYS'].get('user_id', None)
logging.info("survey_question type:%s, device_id:%s, answer_tag:%s" %
(str(data['SYS']['action']), str(device_id), str(tagid_list)))
if len(tagid_list) > 0:
tag_query_results = list(Tag.objects.using(settings.SLAVE1_DB_NAME).filter(
id__in=tagid_list, is_online=True, is_deleted=False,
is_category=False).values_list("id", flat=True))
tag_query_results_multi = [i for i in tagid_list if i in tag_query_results]
is_click = 1
is_vote = 0
reward = 1 if is_click or is_vote else 0
reward = 1 if is_click or is_vote else 0
# 移植老用户的lin信息到ctr特征策略
self.transfer_old_info2ctr_feature_key(device_id)
# 移植老用户的lin信息到ctr特征策略
self.transfer_old_info2ctr_feature_key(device_id)
for i in range(5):
for tag_id in tag_query_results_multi:
self.update_user_linucb_tag_info(reward, device_id, tag_id,
user_feature,
self.linucb_matrix_redis_prefix)
# 获取tag的ctr信息
device_tag_ctr = self.get_device_tag_ctr(device_id, tag_id)
user_feature_ctr = [device_tag_ctr, device_tag_ctr]
self.update_user_linucb_tag_info(reward, device_id, tag_id,
user_feature_ctr,
self.ctr_linucb_matrix_redis_prefix)
for i in range(5):
for tag_id in tag_query_results_multi:
self.update_user_linucb_tag_info(reward, device_id, tag_id,
user_feature,
self.linucb_matrix_redis_prefix)
# 获取tag的ctr信息
device_tag_ctr = self.get_device_tag_ctr(device_id, tag_id)
user_feature_ctr = [device_tag_ctr, device_tag_ctr]
self.update_user_linucb_tag_info(reward, device_id, tag_id,
user_feature_ctr,
self.ctr_linucb_matrix_redis_prefix)
# 更新该用户的推荐tag数据,放在 更新完成user tag行为信息之后
self.update_recommend_tag_list(device_id, user_feature, user_id,
linucb_matrix_prefix=self.linucb_matrix_redis_prefix,
linucb_recommend_tag_prefix=self.linucb_recommend_redis_prefix,
linucb_topic_ids_prefix=self.linucb_recommend_topic_id_prefix,
linucb_pictorial_ids_prefix=self.linucb_recommend_pictorial_id_prefix)
self.update_recommend_tag_list(device_id, user_feature, user_id,
linucb_matrix_prefix=self.ctr_linucb_matrix_redis_prefix,
linucb_recommend_tag_prefix=self.ctr_linucb_recommend_redis_prefix,
linucb_topic_ids_prefix=self.ctr_linucb_recommend_topic_id_prefix,
linucb_pictorial_ids_prefix=self.ctr_linucb_recommend_pictorial_id_prefix)
logging.info("survey_question type:%s, device_id:%s, tagid_list:%s" %
(str(data['SYS']['action']), str(device_id),
str(tag_query_results_multi)))
# 更新该用户的推荐tag数据,放在 更新完成user tag行为信息之后
self.update_recommend_tag_list(device_id, user_feature, user_id,
linucb_matrix_prefix=self.linucb_matrix_redis_prefix,
linucb_recommend_tag_prefix=self.linucb_recommend_redis_prefix,
linucb_topic_ids_prefix=self.linucb_recommend_topic_id_prefix,
linucb_pictorial_ids_prefix=self.linucb_recommend_pictorial_id_prefix)
self.update_recommend_tag_list(device_id, user_feature, user_id,
linucb_matrix_prefix=self.ctr_linucb_matrix_redis_prefix,
linucb_recommend_tag_prefix=self.ctr_linucb_recommend_redis_prefix,
linucb_topic_ids_prefix=self.ctr_linucb_recommend_topic_id_prefix,
linucb_pictorial_ids_prefix=self.ctr_linucb_recommend_pictorial_id_prefix)
logging.info("survey_question type:%s, device_id:%s, tagid_list:%s" %
(str(data['SYS']['action']), str(device_id),
str(tag_query_results_multi)))
# 首页搜索精准匹配标签关键字进linucb
elif 'SYS' in data and 'APP' in data and 'action' in data['SYS'] and data['SYS'][
'action'] == "api/v1/cards/topic":
tag_name = raw_val_dict["APP"].get("query", [])
tag_list = list(Tag.objects.using(settings.SLAVE1_DB_NAME).filter(
tag=tag_name).values_list("id"))
device_id = raw_val_dict["device"]["device_id"]
user_id = raw_val_dict["user_id"] if "user_id" in raw_val_dict else None
self.transfer_update_recommend_tag_list(device_id, user_feature, user_id, tag_list,
5)
# (客户端创建回答,后台创建回答或修改回答关联标签关键字进linucb
elif 'SYS' in data and 'APP' in data and 'action' in data['SYS'] and \
(data['SYS']['action'] in ("venus/community/topic/create", "venus/sun/topic/edit")):
tag_ids = list(raw_val_dict["APP"].get("tag_ids", []))
tag_list = list(Tag.objects.using(settings.SLAVE1_DB_NAME).filter(
id__in=tag_ids, is_online=True, is_deleted=False,
is_category=False).values_list("id"))
device_id = raw_val_dict["device"]["device_id"]
user_id = raw_val_dict["user_id"] if "user_id" in raw_val_dict else None
self.transfer_update_recommend_tag_list(device_id, user_feature, user_id,
tag_list,
10)
# 创建问题关注标签关键字进linucb
elif 'SYS' in data and 'APP' in data and 'action' in data['SYS'] and \
data['SYS']['action'] == "venus/sun/pictorial/edit":
tag_ids = list(raw_val_dict["APP"].get("tag_ids", []))
tag_list = list(Tag.objects.using(settings.SLAVE1_DB_NAME).filter(
id__in=tag_ids, is_online=True, is_deleted=False,
is_category=False).values_list("id"))
device_id = raw_val_dict["device"]["device_id"]
user_id = raw_val_dict["user_id"] if "user_id" in raw_val_dict else None
self.transfer_update_recommend_tag_list(device_id, user_feature, user_id,
tag_list,
20)
else:
if msg:
logging.warning("unknown type msg:%s" % raw_val_dict.get("type", "missing type"))
......@@ -626,3 +659,37 @@ class CollectData(object):
logging_exception()
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
# 用户打标签加分
# 新增四种用户兴趣分行为
# 四种日志均为后端埋点日志
def transfer_update_recommend_tag_list(self, device_id, user_feature, user_id, tag_list, score_loop=1):
if len(tag_list)>0:
is_click = 1
is_vote = 0
reward = 1 if is_click or is_vote else 0
# 移植老用户的lin信息到ctr特征策略
self.transfer_old_info2ctr_feature_key(device_id)
for i in range(score_loop):
for tag_id in tag_list:
self.update_user_linucb_tag_info(reward, device_id, tag_id,
user_feature,
self.linucb_matrix_redis_prefix)
# 获取tag的ctr信息
device_tag_ctr = self.get_device_tag_ctr(device_id, tag_id)
user_feature_ctr = [device_tag_ctr, device_tag_ctr]
self.update_user_linucb_tag_info(reward, device_id, tag_id,
user_feature_ctr, self.ctr_linucb_matrix_redis_prefix)
# 更新该用户的推荐tag数据,放在 更新完成user tag行为信息之后
self.update_recommend_tag_list(device_id, user_feature, user_id,
click_topic_tag_list=tag_list,
linucb_matrix_prefix=self.linucb_matrix_redis_prefix,
linucb_recommend_tag_prefix=self.linucb_recommend_redis_prefix,
linucb_topic_ids_prefix=self.linucb_recommend_topic_id_prefix,
linucb_pictorial_ids_prefix=self.linucb_recommend_pictorial_id_prefix)
self.update_recommend_tag_list(device_id, user_feature, user_id,
click_topic_tag_list=tag_list,
linucb_matrix_prefix=self.ctr_linucb_matrix_redis_prefix,
linucb_recommend_tag_prefix=self.ctr_linucb_recommend_redis_prefix,
linucb_topic_ids_prefix=self.ctr_linucb_recommend_topic_id_prefix,
linucb_pictorial_ids_prefix=self.ctr_linucb_recommend_pictorial_id_prefix)
......@@ -2,6 +2,6 @@ from __future__ import unicode_literals, absolute_import, print_function
import pymysql
from _celery import app as celery_app
from vest import *
pymysql.install_as_MySQLdb()
#__all__ = ('celery_app',)
......@@ -9,6 +9,13 @@ class CeleryTaskRouter(object):
queue_task_map = {
"tapir-alpha": [
'injection.data_sync.tasks.write_to_es',
],
"vest": [
'vest.request.auto_request.click',
'vest.request.auto_request.reply',
'vest.request.auto_request.follow',
'vest.request.auto_request.reply2',
'vest.request.auto_request.pictorial_reply'
]
}
......
from .request import *
\ No newline at end of file
......@@ -6,6 +6,7 @@ from threading import Thread
from vest.request.auto_request import login, time_convs, click
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
from libs.timelib import get_rand_time
def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=6):
......@@ -41,7 +42,8 @@ def batch_handle(auto_click_list):
try:
cookies = login()
if cookies is not None:
click(cookies, topic_id)
click.apply_async(args=(cookies, topic_id), eta=get_rand_time())
# click(cookies, topic_id)
except:
pass
......
......@@ -6,6 +6,7 @@ from threading import Thread
from vest.request.auto_request import login, time_conv_hour, click
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
from libs.timelib import get_rand_time
def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=6):
......@@ -42,7 +43,8 @@ def batch_handle(auto_click_list):
try:
cookies = login()
if cookies is not None:
click(cookies, topic_id)
# click(cookies, topic_id)
click.apply_async(args=(cookies, topic_id), eta=get_rand_time(hourup=1))
except:
pass
......
......@@ -6,6 +6,7 @@ from threading import Thread
from vest.request.auto_request import login, time_convs, follow
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
from libs.timelib import get_rand_time
def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=3):
......@@ -28,7 +29,9 @@ def batch_handle(auto_follow_list):
try:
cookies = login()
if cookies is not None:
follow(cookies, user_id)
# follow(cookies, user_id)
follow.apply_async(args=(cookies, user_id), eta=get_rand_time())
except:
pass
......
......@@ -6,6 +6,7 @@ from threading import Thread
from vest.request.auto_request import login, time_convs, follow
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
from libs.timelib import get_rand_time
def get_commnet_id(numtime, numtime2):
......@@ -27,7 +28,9 @@ def batch_handle(auto_follow_list):
try:
cookies = login()
if cookies is not None:
follow(cookies, user_id)
# follow(cookies, user_id)
follow.apply_async(args=(cookies, user_id), eta=get_rand_time())
except:
pass
......
......@@ -6,7 +6,7 @@ from threading import Thread
from vest.request.auto_request import login, time_conv_hour, follow
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
from libs.timelib import get_rand_time
def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=6):
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
......@@ -40,7 +40,9 @@ def batch_handle(auto_follow_list):
try:
cookies = login()
if cookies is not None:
follow(cookies, user_id)
# follow(cookies, user_id)
follow.apply_async(args=(cookies, user_id), eta=get_rand_time(hourup=1))
except:
pass
......
......@@ -5,6 +5,7 @@ from vest.request.auto_request import login, follow, time_conv_minute
from vest.request.auto_request import host, user, db, passwd
from vest.data.majia_user_ids import majia_user_ids_dict
from libs.error import logging_exception
from libs.timelib import get_rand_time
def get_user_id(numtime):
......@@ -28,7 +29,9 @@ def auto_follow_per_5m_by_followed():
user_id = user[0]
cookies = login(str(majia_user_ids_dict.get(str(user[1]))))
if cookies is not None:
follow(cookies, user_id)
# follow(cookies, user_id)
follow.apply_async(args=(cookies, user_id), eta=get_rand_time())
except:
pass
......
......@@ -8,6 +8,7 @@ from vest.request.auto_request import login, pictorial_reply, get_majia, get_pic
from vest.request.auto_request import host, user, db, passwd
from vest.data.topic_models import get_pictorial_tag_by_id
from libs.timelib import get_rand_time
"""
榜单新增内容(仅限在线的)
......@@ -38,8 +39,8 @@ def get_data(numtime1, numtime2):
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT pictorial_id FROM community_pictorial_topic WHERE is_online=1 and (create_time >= '%s' and create_time < '%s') group by pictorial_id " % (
numtime1, numtime2))
"SELECT id FROM community_pictorial WHERE is_online=1 and (create_time >= '%s' and create_time < '%s') " % (
numtime2, numtime1))
res = cursor.fetchall()
return res and [r for r, in res] or []
......@@ -55,16 +56,15 @@ def batch_handle(pictorial_id_list):
cookies = login()
if cookies is not None:
comment = judge_pictorial_info_get_comment(pictorial_id)
pictorial_reply(cookies, pictorial_id, comment)
# pictorial_reply(cookies, pictorial_id, comment)
pictorial_reply.apply_async(args=(cookies, pictorial_id, comment), eta=get_rand_time())
except:
pass
def auto_reply_per_1d_to_pictorial():
# 问题自动增加回答
# todo topic_vote_cnt和community_pictorial_topic
# todo 1天前发的问题:[0-1]个评论 6天前发的问题:[0-1]个评论 这个是什么鬼
# todo 怎么禁止作者评论
pictorial_id_list = []
try:
logging.info("comment offline pictorial")
......
import pymysql
import traceback
import logging
import json
import random
from threading import Thread
from vest.request.auto_request import login, time_convs, get_answer_data, reply_answer, get_majia, \
set_reply_to_redis, judge_topic_info_get_comment, reply
set_reply_to_redis, judge_topic_info_get_comment, reply, reply2
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
import random
from libs.timelib import get_rand_time
def get_data(numtime, numtime2, content_level_low, content_level_top):
......@@ -31,7 +33,19 @@ def batch_handle(topic_id_list):
cookies = login()
if cookies is not None:
comment = judge_topic_info_get_comment(topic_id)
reply(cookies, topic_id, comment)
if comment:
# reply(cookies, topic_id, comment)
reply.apply_async(args=(cookies, topic_id, comment), eta=get_rand_time())
else:
comment1, comment2 = get_answer_data()
response = reply_answer(cookies, topic_id, comment1)
response = json.loads(response)
cookies = login()
reply_id = response["data"]["id"]
reply2.apply_async(args=(cookies, topic_id, comment2, reply_id), eta=get_rand_time())
except:
logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc())
......
import pymysql
import traceback
import logging
import json
from threading import Thread
from vest.request.auto_request import login, time_conv_hour, get_answer_data, reply_answer, get_majia, \
set_reply_to_redis, judge_topic_info_get_comment, reply
set_reply_to_redis, judge_topic_info_get_comment, reply, reply2
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
from libs.timelib import get_rand_time
import random
......@@ -14,7 +16,7 @@ def get_data(numtime, numtime2):
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT user_id FROM topic WHERE is_online=1 and (create_time >= '%s' and create_time <= '%s' )" % (
"SELECT id FROM topic WHERE is_online=1 and (create_time >= '%s' and create_time <= '%s' )" % (
numtime2, numtime))
res = cursor.fetchall()
return res and [r for r, in res] or []
......@@ -30,7 +32,17 @@ def batch_handle(topic_id_list):
cookies = login()
if cookies is not None:
comment = judge_topic_info_get_comment(topic_id)
reply(cookies, topic_id, comment)
if comment:
# reply(cookies, topic_id, comment)
reply.apply_async(args=(cookies, topic_id, comment), eta=get_rand_time(hourup=1))
else:
comment1, comment2 = get_answer_data()
response = reply_answer(cookies, topic_id, comment1)
response = json.loads(response)
cookies = login()
reply_id = response["data"]["id"]
reply2.apply_async(args=(cookies, topic_id, comment2, reply_id), eta=get_rand_time(hourup=1))
except:
logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc())
......
from .auto_request import *
\ No newline at end of file
......@@ -7,6 +7,7 @@ import logging
import json
import redis
import smtplib
from celery import shared_task
from libs.cache import redis_client
from email.mime.text import MIMEText
from email.utils import formataddr
......@@ -113,6 +114,7 @@ def logins(user_id):
return None
@shared_task
def click(cookies_get, id):
# 点赞
try:
......@@ -137,6 +139,7 @@ def click(cookies_get, id):
cookies=cookies_get,
data=post_dict)
print(response.text)
logging.info("response.text:%s" % response.text)
get_error(response.text, "click", id)
......@@ -145,6 +148,7 @@ def click(cookies_get, id):
logging.error("catch exception,logins:%s" % traceback.format_exc())
@shared_task
def reply(cookies_get, id, content):
try:
post_dict = {
......@@ -156,6 +160,7 @@ def reply(cookies_get, id, content):
cookies=cookies_get,
data=post_dict)
print(response.text)
logging.info("response.text:%s" % response.text)
get_error(response.text, "reply", id)
except:
......@@ -267,6 +272,7 @@ def get_comments():
return None
@shared_task
def follow(cookies_get, id):
try:
post_dict = {
......@@ -277,6 +283,7 @@ def follow(cookies_get, id):
cookies=cookies_get,
data=post_dict)
print(response.text)
logging.info("response.text:%s" % response.text)
get_error(response.text, "follow", id)
except:
......@@ -431,6 +438,7 @@ def set_reply_to_redis():
logging.error("catch exception,logins:%s" % traceback.format_exc())
@shared_task
def reply2(cookies_get, id, content, replied_id):
try:
post_dict = {
......@@ -443,6 +451,7 @@ def reply2(cookies_get, id, content, replied_id):
cookies=cookies_get,
data=post_dict)
print(response.text)
logging.info("response.text:%s" % response.text)
get_error(response.text, "reply2", id)
except:
......@@ -450,6 +459,7 @@ def reply2(cookies_get, id, content, replied_id):
logging.error("catch exception,logins:%s" % traceback.format_exc())
@shared_task
def pictorial_reply(cookies_get, id, content):
try:
post_dict = {
......@@ -461,6 +471,7 @@ def pictorial_reply(cookies_get, id, content):
cookies=cookies_get,
data=post_dict)
print(response.text)
logging.info("response.text:%s" % response.text)
get_error(response.text, "pictorial_reply", id)
except:
......@@ -604,7 +615,9 @@ def judge_topic_info_get_comment(topic_id):
comment = get_face_comment()
# 原始评论
else:
comment = get_comment()
# 返回空就会去拿多级评论
if random.randint(0, 1):
comment = get_comment()
else:
# 判断有没有商品信息
......@@ -622,7 +635,9 @@ def judge_topic_info_get_comment(topic_id):
comment = get_face_comment()
# 原始评论
else:
comment = get_comment()
# 返回空就会去拿多级评论
if random.randint(0, 1):
comment = get_comment()
logging.info("get judge_topic_info_get_comment:%s" % comment)
return comment
......
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