Commit 63a42a94 authored by 吴升宇's avatar 吴升宇

Merge branch 'wsy3' into 'master'

Wsy3

See merge request !533
parents 0eec3594 02c75432
......@@ -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,3 @@ celery -A physical beat
### physical策略端脚本
在Alp-Test-Cos-test001服务器上,通过crontab -l查看
更新脚本
```bash
cp crontab.py /data/log/physical/app/crontab.py
python /data/log/physical/app/crontab.py
python /data/log/physical/app/crontabs.py
```
\ No newline at end of file
......@@ -15,44 +15,34 @@ 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"
# "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",
"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",
# "* * * 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"
]
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"]
###随机生成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()
......@@ -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'
]
}
......
......@@ -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()
......
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):
......@@ -17,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(
......@@ -28,7 +29,7 @@ def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=6):
"SELECT pictorial_id FROM community_pictorial_topic where topic_id=%s limit 1" % i)
pictorial_id = cursor.fetchall()
if pictorial_id is not None:
if pictorial_id:
topic_ids.append((i, pictorial_id[0]))
else:
topic_ids.append((i, 0))
......@@ -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):
......@@ -18,10 +19,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(
......@@ -29,7 +30,7 @@ def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=6):
"SELECT pictorial_id FROM community_pictorial_topic where topic_id=%s limit 1" % i)
pictorial_id = cursor.fetchall()
if pictorial_id is not None:
if pictorial_id:
topic_ids.append((i, pictorial_id[0]))
else:
topic_ids.append((i, 0))
......@@ -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
......
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
from libs.timelib import get_rand_time
"""
榜单新增内容(仅限在线的)
每半小时一次
过去半小时之内,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 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 []
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)
pictorial_reply.apply_async(args=(cookies, pictorial_id, comment), eta=get_rand_time())
except:
pass
def auto_reply_per_1d_to_pictorial():
# 问题自动增加回答
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())
logging.info('auto_click_per_2h_by_post: len %s' % len(pictorial_id_list))
print('auto_click_per_2h_by_post: len %s' % len(pictorial_id_list))
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
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, reply2
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_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 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)
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())
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())
logging.info('auto_click_per_2h_by_post: len %s' % len(topic_id_list))
print('auto_click_per_2h_by_post: len %s' % len(topic_id_list))
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
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, 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
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 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)
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())
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())
logging.info('auto_click_per_2h_by_post: len %s' % len(topic_id_list))
print('auto_click_per_2h_by_post: len %s' % len(topic_id_list))
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
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,8 +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:
# 判断有没有商品信息
......@@ -623,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
......
......@@ -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