Commit 7e45a44a authored by 吴升宇's avatar 吴升宇

add auto reply

parent dacc6546
......@@ -19,7 +19,8 @@ ontime_list = [
"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"
# "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"
]
......@@ -27,21 +28,24 @@ 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 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",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m answer_reply5",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m answer_reply7",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m yesterday_topic_reply",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m before_yesterday_topic_reply",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m three_days_ago_topic_reply",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m five_days_ago_topic_reply",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m seven_days_ago_reply",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment1",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment3",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment2",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment5",
"* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment7"]
"* * * 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"
# "* * * 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",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m answer_reply5",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m answer_reply7",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m yesterday_topic_reply",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m before_yesterday_topic_reply",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m three_days_ago_topic_reply",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m five_days_ago_topic_reply",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m seven_days_ago_reply",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment1",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment3",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment2",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment5",
# "* * * source /srv/envs/physical/bin/activate && cd /srv/apps/physical && python manage.py trans2es_mapping2es -m reply_comment7"
]
......
......@@ -7,7 +7,8 @@ import traceback
import logging
from libs.es import ESPerform
from trans2es.type_info import get_type_info_map, TypeInfo
from vest.reply import true_comment_one, true_comment_two, true_comment_three, one_seven_topic_comment
from vest.reply import true_comment_one, true_comment_two, true_comment_three, one_seven_topic_comment,\
auto_reply_per_1d_to_pictorial, auto_reply_per_1d_to_topic, auto_reply_per_2h_to_topic
from vest.click import true_click_five, true_click_two, true_click_four, true_click_one, true_click_three, \
one_seven_star_topic, auto_click_per_1d_by_post, auto_click_per_2h_by_post
from vest.follow import auto_follow, auto_follow_new, auto_follow_per_5m_by_followed, \
......@@ -142,6 +143,15 @@ class Command(BaseCommand):
if options["mvest"] == "vest_click_reply":
vest_click_reply.vest_click_reply()
# 自动评论
if options["mvest"] == "auto_reply_per_1d_to_pictorial":
auto_reply_per_1d_to_pictorial.auto_reply_per_1d_to_pictorial()
if options["mvest"] == "auto_reply_per_2h_to_topic":
auto_reply_per_2h_to_topic.auto_reply_per_2h_to_topic()
if options["mvest"] == "auto_reply_per_1d_to_topic":
auto_reply_per_1d_to_topic.auto_reply_per_1d_to_topic()
# 榜单评论
if options["mvest"] == "principal_offline_comment1":
principal_offline_comment1.principal_offline_comment1()
......
......@@ -17,10 +17,10 @@ def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=6):
cursor.execute(
"select t.id from topic t left join user_extra u on t.user_id = u.user_id "
"where u.is_shadow=0 and t.create_time > '%s' and t.create_time < '%s' and is_online=1 "
"where u.is_shadow=0 and t.create_time > '%s' and t.create_time < '%s' and t.is_online=1 "
"and t.content_level >= %s and t.content_level <= %s " % (numtime, numtime2, str(content_level_low), str(content_level_top)))
res = cursor.fetchone()
res = cursor.fetchall()
for i, in res:
cursor.execute(
......
......@@ -18,10 +18,10 @@ def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=6):
cursor.execute(
"select t.id from topic t left join user_extra u on t.user_id = u.user_id "
"where u.is_shadow=0 and t.create_time > '%s' and t.create_time < '%s' and is_online=1 "
"where u.is_shadow=0 and t.create_time > '%s' and t.create_time < '%s' and t.is_online=1 "
"and t.content_level >= %s and t.content_level <= %s " % (numtime, numtime2, str(content_level_low), str(content_level_top)))
res = cursor.fetchone()
res = cursor.fetchall()
for i, in res:
cursor.execute(
......
import pymysql
import random
import traceback
import logging
from threading import Thread
from vest.request.auto_request import login, pictorial_reply, get_majia, get_pictorial_comment, time_convs, \
judge_pictorial_info_get_comment
from vest.request.auto_request import host, user, db, passwd
from vest.data.topic_models import get_pictorial_tag_by_id
"""
榜单新增内容(仅限在线的)
每半小时一次
过去半小时之内,if
新增在线帖子(既包含马甲用户、又包含普通用户)达到1个时,插入{1,2}条评论
新增在线帖子(既包含马甲用户、又包含普通用户)达到2-5个时,插入{2,3}条评论
新增在线帖子(既包含马甲用户、又包含普通用户)达到>5张时,插入{3,5}条评论
(注意评论作者需要是马甲用户)
过去半小时之内,if
本榜单有新增投票(既包含马甲用户、又包含普通用户),插入{1,2}条评论
评论取自单独的榜单评论列表,并自动随机关联马甲
注意需要禁止本帖作者评论
"""
def get_data(numtime1, numtime2):
try:
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT pictorial_id ,count(*) as count FROM community_pictorial_topic WHERE is_online=1 and (create_time >= '%s' and create_time < '%s') group by pictorial_id " % (
numtime1, numtime2))
res = cursor.fetchall()
return res and [r for r, in res] or []
except:
logging.error("catch exception,get_data:%s" % traceback.format_exc())
return []
def batch_handle(pictorial_id_list):
for pictorial_id in pictorial_id_list:
try:
cookies = login()
if cookies is not None:
comment = judge_pictorial_info_get_comment(pictorial_id)
pictorial_reply(cookies, pictorial_id, comment)
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")
numtime1, numtime2 = time_convs(1, 1)
pictorial_ids = get_data(numtime1, numtime2)
for pictorial_id in pictorial_ids:
random_num = random.randint(0, 1)
for i in range(random_num):
pictorial_id_list.append(pictorial_id)
numtime1, numtime2 = time_convs(2, 6)
pictorial_ids = get_data(numtime1, numtime2)
for pictorial_id in pictorial_ids:
random_num = random.randint(0, 1)
for i in range(random_num):
pictorial_id_list.append(pictorial_id)
else:
logging.error("catch exception,main:%s" % traceback.format_exc())
except:
logging.error("catch exception,main:%s" % traceback.format_exc())
total = len(pictorial_id_list)
limit = (total + 10) // 10
for start in range(0, total, limit):
batch = pictorial_id_list[start:start + limit]
t = Thread(target=batch_handle, args=[batch])
t.start()
\ No newline at end of file
import pymysql
import traceback
import logging
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
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
import random
def get_data(numtime, numtime2, content_level_low, content_level_top):
try:
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT user_id,id FROM topic WHERE is_online=1 and (create_time >= '%s' and create_time <= '%s' )"
"and content_level>= %s and content_level<= %s" % (
numtime2, numtime, str(content_level_low), str(content_level_top)))
res = cursor.fetchall()
return res and [r for r, in res] or []
except:
logging.error("catch exception,get_data:%s" % traceback.format_exc())
return []
def batch_handle(topic_id_list):
for topic_id in topic_id_list:
try:
cookies = login()
if cookies is not None:
comment = judge_topic_info_get_comment(topic_id)
reply(cookies, topic_id, comment)
except:
logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc())
def auto_reply_per_1d_to_topic():
topic_id_list = []
try:
# 1-3星及无星:
# 1天前发的帖子:[1-3]个评论
numtime1, numtime2 = time_convs(1, 1)
topic_ids = get_data(numtime1, numtime2, 0, 3)
for topic_id in topic_ids:
random_num = random.randint(1, 3)
for num in range(random_num):
topic_id_list.append(topic_id)
# 2-6天前发的帖子:[0-1]个评论
numtime1, numtime2 = time_convs(2, 6)
topic_ids = get_data(numtime1, numtime2, 0, 3)
for topic_id in topic_ids:
random_num = random.randint(0, 1)
for num in range(random_num):
topic_id_list.append(topic_id)
# 4-6星:
# 1天前发的帖子:[1-6]个评论
numtime1, numtime2 = time_convs(1, 1)
topic_ids = get_data(numtime1, numtime2, 4, 6)
for topic_id in topic_ids:
random_num = random.randint(1, 6)
for num in range(random_num):
topic_id_list.append(topic_id)
# 2-6天前发的帖子:[1-3]个评论
numtime1, numtime2 = time_convs(2, 6)
topic_ids = get_data(numtime1, numtime2, 4, 6)
for topic_id in topic_ids:
random_num = random.randint(1, 3)
for num in range(random_num):
topic_id_list.append(topic_id)
except:
logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc())
total = len(topic_id_list)
limit = (total + 10) // 10
for start in range(0, total, limit):
batch = topic_id_list[start:start + limit]
t = Thread(target=batch_handle, args=[batch])
t.start()
\ No newline at end of file
import pymysql
import traceback
import logging
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
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
import random
def get_data(numtime, numtime2):
try:
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT user_id,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 []
except:
logging.error("catch exception,get_data:%s" % traceback.format_exc())
return []
def batch_handle(topic_id_list):
for topic_id in topic_id_list:
try:
cookies = login()
if cookies is not None:
comment = judge_topic_info_get_comment(topic_id)
reply(cookies, topic_id, comment)
except:
logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc())
def auto_reply_per_2h_to_topic():
topic_id_list = []
try:
numtime1, numtime2 = time_conv_hour(0, 2)
topic_ids = get_data(numtime1, numtime2)
for topic_id in topic_ids:
random_num = random.randint(1, 2)
for num in range(random_num):
topic_id_list.append(topic_id)
except:
logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc())
total = len(topic_id_list)
limit = (total + 10) // 10
for start in range(0, total, limit):
batch = topic_id_list[start:start + limit]
t = Thread(target=batch_handle, args=[batch])
t.start()
\ No newline at end of file
......@@ -604,7 +604,6 @@ def judge_topic_info_get_comment(topic_id):
comment = get_face_comment()
# 原始评论
else:
comment = get_comment()
else:
......
......@@ -16,6 +16,31 @@ def index_first():
return None
def get_cook_by_email(email):
try:
cookies = index_first()
post_dict = {
'account_type': 2,
'pwd': '123456',
'email': email
}
response = requests.post(
url=settings.LOGIN_URL,
data=post_dict,
cookies=cookies
)
headers = response.headers
print(response.text)
cook = headers['Set-Cookie'].split(";")
cook = cook[0].split('=')[1]
logging.info("response.text :%s" % response.text)
return cook
except:
logging.error("index_first:%s" % traceback.format_exc())
return None
def get_cook():
try:
data = open("/srv/apps/physical/vest/data/vest_user_email.txt")
......
......@@ -149,4 +149,33 @@ def follow(cookies_get, id):
print(response.text)
follow({'sessionid': 'qsukyafj7ub2f43f33g2jm0kkvqf0sa7'}, 241765445)
def index_first():
try:
r1 = requests.get("http://earth.gmapp.env/api/account/login_pwd")
return r1.cookies.get_dict()
except:
return None
def get_cook_by_email(email):
cookies = index_first()
post_dict = {
'account_type': 2,
'pwd': '123456',
'email': email
}
response = requests.post(
url="http://earth.gmapp.env/api/account/login_pwd",
data=post_dict,
cookies=cookies
)
headers = response.headers
# print(response.text)
cook = headers['Set-Cookie'].split(";")
cook = cook[0].split('=')[1]
return cook
res = get_cook_by_email("s_gXRMNW@shadow.com")
print(res)
\ No newline at end of file
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