Commit 3ead6d7b authored by 吴升宇's avatar 吴升宇

fix auto follow

parent 7e949071
...@@ -2,36 +2,30 @@ import pymysql ...@@ -2,36 +2,30 @@ import pymysql
import random import random
import traceback import traceback
import logging import logging
from threading import Thread
from vest.request.auto_request import login, time_convs, follow from vest.request.auto_request import login, time_convs, follow
from vest.request.auto_request import host, user, db, passwd from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception from libs.error import logging_exception
def get_commnet_id(numtime, numtime2): def get_commnet_id(numtime, numtime2, content_level_low=0, content_level_top=3):
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306) pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor() cursor = pc.cursor()
# 发贴后 # 发贴后
cursor.execute( cursor.execute(
"select t.user_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' " % (numtime, numtime2)) "select t.user_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 t.content_level >= %s and t.content_level <= %s " % (numtime, numtime2, str(content_level_low), str(content_level_top)))
res = cursor.fetchall() res = cursor.fetchall()
return res and [i for i, in res] or [] return res and [i for i, in res] or []
def auto_follow(time_start, time_end, num_low, num_top, num_one=None): def batch_handle(auto_follow_list):
for user_id in auto_follow_list:
try: try:
user_ids = get_commnet_id(time_start, time_end)
for user_id in user_ids:
follow_num = random.randint(num_low, num_top)
if num_one:
if follow_num == 1:
cookies = login()
if cookies is not None:
follow(cookies, user_id)
else:
for i in range(follow_num):
cookies = login() cookies = login()
if cookies is not None: if cookies is not None:
follow(cookies, user_id) follow(cookies, user_id)
...@@ -39,91 +33,70 @@ def auto_follow(time_start, time_end, num_low, num_top, num_one=None): ...@@ -39,91 +33,70 @@ def auto_follow(time_start, time_end, num_low, num_top, num_one=None):
pass pass
def auto_follow_per_1d_by_post(): def auto_follow_per_1d_by_post():
# 发帖触发自动加粉丝 # 发帖触发自动加粉丝
auto_follow_list = []
try: try:
# 0-3星 # 0-3星
# 1天前发的帖子:[2-6]个粉丝 # 1天前发的帖子:[2-6]个粉丝
numtime1, numtime2 = time_convs(1, 1) numtime1, numtime2 = time_convs(1, 1)
user_ids = get_commnet_id(numtime2, numtime1) user_ids = get_commnet_id(numtime2, numtime1, content_level_low=0, content_level_top=3)
try:
for user_id in user_ids: for user_id in user_ids:
follow_num = random.randint(2, 6) follow_num = random.randint(2, 6)
for i in range(follow_num): for i in range(follow_num):
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, user_id)
except:
pass
# 2-15天前发的帖子:[0-1]个粉丝 # 2-15天前发的帖子:[0-1]个粉丝
numtime1, numtime2 = time_convs(2, 15) numtime1, numtime2 = time_convs(2, 15)
user_ids = get_commnet_id(numtime2, numtime1) user_ids = get_commnet_id(numtime2, numtime1, content_level_low=0, content_level_top=3)
try:
for user_id in user_ids: for user_id in user_ids:
follow_num = random.randint(0, 1) follow_num = random.randint(0, 1)
for i in range(follow_num): for i in range(follow_num):
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, user_id)
except:
pass
# 15天前或更早发的帖子:每隔11天[0-2]个粉丝 # 15天前或更早发的帖子:每隔11天[0-2]个粉丝
numtime1, numtime2 = time_convs(2, 15) numtime1, numtime2 = time_convs(2, 15)
user_ids = get_commnet_id('0', numtime2) user_ids = get_commnet_id('0', numtime2, content_level_low=0, content_level_top=3)
try:
for user_id in user_ids: for user_id in user_ids:
follow_num = random.randint(1, 6) follow_num = random.randint(1, 6)
if follow_num == 6: if follow_num == 6:
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, user_id)
except:
pass
# 4-6星 # 4-6星
# 1天前发的帖子:[5-10]个粉丝 # 1天前发的帖子:[5-10]个粉丝
numtime1, numtime2 = time_convs(1, 1) numtime1, numtime2 = time_convs(1, 1)
user_ids = get_commnet_id(numtime2, numtime1) user_ids = get_commnet_id(numtime2, numtime1, content_level_low=4, content_level_top=6)
try:
for user_id in user_ids: for user_id in user_ids:
follow_num = random.randint(5, 10) follow_num = random.randint(5, 10)
for i in range(follow_num): for i in range(follow_num):
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, user_id)
except:
pass
# 2-15天前发的帖子:[0-5]个粉丝 # 2-15天前发的帖子:[0-5]个粉丝
numtime1, numtime2 = time_convs(2, 15) numtime1, numtime2 = time_convs(2, 15)
user_ids = get_commnet_id(numtime2, numtime1) user_ids = get_commnet_id(numtime2, numtime1, content_level_low=4, content_level_top=6)
try:
for user_id in user_ids: for user_id in user_ids:
follow_num = random.randint(0, 5) follow_num = random.randint(0, 5)
for i in range(follow_num): for i in range(follow_num):
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, user_id)
except:
pass
# 15天前或更早发的帖子:每隔11天[0-2]个粉丝 # 15天前或更早发的帖子:每隔11天[0-2]个粉丝
numtime1, numtime2 = time_convs(2, 15) numtime1, numtime2 = time_convs(2, 15)
user_ids = get_commnet_id('0', numtime2) user_ids = get_commnet_id('0', numtime2, content_level_low=4, content_level_top=6)
try:
for user_id in user_ids: for user_id in user_ids:
follow_num = random.randint(1, 6) follow_num = random.randint(1, 6)
if follow_num == 6: if follow_num == 6:
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, user_id)
except:
pass
except: except:
logging_exception() logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc()) logging.error("catch exception,main:%s" % traceback.format_exc())
logging.info('auto_follow_per_1d_by_post: len %s' % len(auto_follow_list))
print('auto_follow_per_1d_by_post: len %s' % len(auto_follow_list))
total = len(auto_follow_list)
limit = (total + 10) // 10
for start in range(0, total, limit):
batch = auto_follow_list[start:start + limit]
t = Thread(target=batch_handle, args=[batch])
t.start()
...@@ -2,6 +2,7 @@ import pymysql ...@@ -2,6 +2,7 @@ import pymysql
import random import random
import traceback import traceback
import logging import logging
from threading import Thread
from vest.request.auto_request import login, time_convs, follow from vest.request.auto_request import login, time_convs, follow
from vest.request.auto_request import host, user, db, passwd from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception from libs.error import logging_exception
...@@ -14,71 +15,63 @@ def get_commnet_id(numtime, numtime2): ...@@ -14,71 +15,63 @@ def get_commnet_id(numtime, numtime2):
# 注册后 # 注册后
cursor.execute( cursor.execute(
"select user_id from account_user WHERE create_time > '%s' and create_time < '%s' " % (numtime, numtime2)) "select a.user_id from account_user a left join user_extra u on a.user_id = u.user_id "
"WHERE a.create_time > '%s' and a.create_time < '%s' and u.is_shadow = 0 " % (numtime, numtime2))
data_new_user = cursor.fetchall() res = cursor.fetchall()
return res and [i for i, in res] or []
all_data = list(data_new_user)
user_id_list = [] def batch_handle(auto_follow_list):
for i in all_data and all_data: for user_id in auto_follow_list:
cursor.execute( try:
"select user_id from user_extra where user_id =" + str(i[0]) + " and is_shadow =0 ") cookies = login()
data = cursor.fetchall() if cookies is not None:
user_id = list(data) follow(cookies, user_id)
if len(user_id) == 0: except:
user_id_list.append(i) pass
logging.info("Database version : %s " % user_id_list)
pc.close()
return user_id_list
def auto_follow_per_1d_by_regist(): def auto_follow_per_1d_by_regist():
# 注册事件触发自动加粉丝 # 注册事件触发自动加粉丝
auto_follow_list = []
try: try:
# 1天前注册:[1-3]个粉丝 # 1天前注册:[1-3]个粉丝
numtime1, numtime2 = time_convs(1, 1) numtime1, numtime2 = time_convs(1, 1)
user_id = get_commnet_id(numtime2, numtime1) user_ids= get_commnet_id(numtime2, numtime1)
try: for user_id in user_ids:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(1, 3) follow_num = random.randint(1, 3)
for i in range(follow_num): for i in range(follow_num):
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, id)
except:
pass
# 2-10天前注册:[0-1]个粉丝 # 2-10天前注册:[0-1]个粉丝
numtime1, numtime2 = time_convs(2, 12) numtime1, numtime2 = time_convs(2, 12)
user_id = get_commnet_id(numtime2, numtime1) user_ids = get_commnet_id(numtime2, numtime1)
try: for user_id in user_ids:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(0, 1) follow_num = random.randint(0, 1)
for i in range(follow_num): for i in range(follow_num):
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, id)
except:
pass
# 10天前注册:每隔12天[0-1]个赞 # 10天前注册:每隔12天[0-1]个赞
numtime1, numtime2 = time_convs(1, 12) numtime1, numtime2 = time_convs(1, 12)
user_id = get_commnet_id('0', numtime2) user_ids = get_commnet_id('0', numtime2)
try: for user_id in user_ids:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(1, 24) follow_num = random.randint(1, 24)
if follow_num == 12: if follow_num == 12:
cookies = login() auto_follow_list.append(user_id)
if cookies is not None:
follow(cookies, id)
except:
pass
except: except:
logging_exception() logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc()) logging.error("catch exception,main:%s" % traceback.format_exc())
logging.info('auto_follow_per_1d_by_regist: len %s' % len(auto_follow_list))
print('auto_follow_per_1d_by_regist: len %s' % len(auto_follow_list))
total = len(auto_follow_list)
limit = (total + 10) // 10
for start in range(0, total, limit):
batch = auto_follow_list[start:start + limit]
t = Thread(target=batch_handle, args=[batch])
t.start()
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