Commit cb5cf5cf authored by 吴升宇's avatar 吴升宇

Merge branch 'wsy1' into 'test'

Wsy1

See merge request !517
parents d9ddf914 3ead6d7b
import datetime
def time_conv(minutest, minutest2):
try:
now = datetime.datetime.now()
yes_time = now - datetime.timedelta(minutes=minutest)
yes_time2 = now - datetime.timedelta(minutes=minutest2)
return yes_time, yes_time2
except:
return None
numtime1, numtime2 = time_conv(1, 5)
print(numtime1, numtime2)
......@@ -2,128 +2,101 @@ import pymysql
import random
import traceback
import logging
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
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)
cursor = pc.cursor()
# 发贴后
cursor.execute(
"select user_id from topic WHERE create_time > '%s' and 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)))
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 = []
for i in all_data and all_data:
cursor.execute(
"select user_id from user_extra where user_id =" + str(i[0]) + " and is_shadow =0 ")
data = cursor.fetchall()
user_id = list(data)
if (user_id and user_id[0][1] == 0) or len(user_id) == 0:
user_id_list.append(i)
logging.info("Database version : %s " % user_id_list)
pc.close()
return user_id_list
def batch_handle(auto_follow_list):
for user_id in auto_follow_list:
try:
cookies = login()
if cookies is not None:
follow(cookies, user_id)
except:
pass
def auto_follow_per_1d_by_post():
# 发帖触发自动加粉丝
auto_follow_list = []
try:
# 0-3星
# 1天前发的帖子:[2-6]个粉丝
numtime1, numtime2 = time_convs(1, 1)
user_id = get_commnet_id(numtime2, numtime1, )
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(2, 6)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids = get_commnet_id(numtime2, numtime1, content_level_low=0, content_level_top=3)
for user_id in user_ids:
follow_num = random.randint(2, 6)
for i in range(follow_num):
auto_follow_list.append(user_id)
# 2-15天前发的帖子:[0-1]个粉丝
numtime1, numtime2 = time_convs(2, 15)
user_id = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(0, 1)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids = get_commnet_id(numtime2, numtime1, content_level_low=0, content_level_top=3)
for user_id in user_ids:
follow_num = random.randint(0, 1)
for i in range(follow_num):
auto_follow_list.append(user_id)
# 15天前或更早发的帖子:每隔11天[0-2]个粉丝
numtime1, numtime2 = time_convs(2, 15)
user_id = get_commnet_id('0', numtime2)
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(1, 6)
if follow_num == 6:
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids = get_commnet_id('0', numtime2, content_level_low=0, content_level_top=3)
for user_id in user_ids:
follow_num = random.randint(1, 6)
if follow_num == 6:
auto_follow_list.append(user_id)
# 4-6星
# 1天前发的帖子:[5-10]个粉丝
numtime1, numtime2 = time_convs(1, 1)
user_id = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(5, 10)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids = get_commnet_id(numtime2, numtime1, content_level_low=4, content_level_top=6)
for user_id in user_ids:
follow_num = random.randint(5, 10)
for i in range(follow_num):
auto_follow_list.append(user_id)
# 2-15天前发的帖子:[0-5]个粉丝
numtime1, numtime2 = time_convs(2, 15)
user_id = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(0, 5)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids = get_commnet_id(numtime2, numtime1, content_level_low=4, content_level_top=6)
for user_id in user_ids:
follow_num = random.randint(0, 5)
for i in range(follow_num):
auto_follow_list.append(user_id)
# 15天前或更早发的帖子:每隔11天[0-2]个粉丝
numtime1, numtime2 = time_convs(2, 15)
user_id = get_commnet_id('0', numtime2)
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(1, 6)
if follow_num == 6:
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids = get_commnet_id('0', numtime2, content_level_low=4, content_level_top=6)
for user_id in user_ids:
follow_num = random.randint(1, 6)
if follow_num == 6:
auto_follow_list.append(user_id)
except:
logging_exception()
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
import random
import traceback
import logging
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
......@@ -14,71 +15,63 @@ def get_commnet_id(numtime, numtime2):
# 注册后
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 = []
for i in all_data and all_data:
cursor.execute(
"select user_id from user_extra where user_id =" + str(i[0]) + " and is_shadow =0 ")
data = cursor.fetchall()
user_id = list(data)
if (user_id and user_id[0][1] == 0) or len(user_id) == 0:
user_id_list.append(i)
logging.info("Database version : %s " % user_id_list)
pc.close()
return user_id_list
def batch_handle(auto_follow_list):
for user_id in auto_follow_list:
try:
cookies = login()
if cookies is not None:
follow(cookies, user_id)
except:
pass
def auto_follow_per_1d_by_regist():
# 注册事件触发自动加粉丝
auto_follow_list = []
try:
# 1天前注册:[1-3]个粉丝
numtime1, numtime2 = time_convs(1, 1)
user_id = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(1, 3)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids= get_commnet_id(numtime2, numtime1)
for user_id in user_ids:
follow_num = random.randint(1, 3)
for i in range(follow_num):
auto_follow_list.append(user_id)
# 2-10天前注册:[0-1]个粉丝
numtime1, numtime2 = time_convs(2, 12)
user_id = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(0, 1)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids = get_commnet_id(numtime2, numtime1)
for user_id in user_ids:
follow_num = random.randint(0, 1)
for i in range(follow_num):
auto_follow_list.append(user_id)
# 10天前注册:每隔12天[0-1]个赞
numtime1, numtime2 = time_convs(1, 12)
user_id = get_commnet_id('0', numtime2)
try:
for j in user_id and user_id:
id = int(j[0])
follow_num = random.randint(1, 24)
if follow_num == 12:
cookies = login()
if cookies is not None:
follow(cookies, id)
except:
pass
user_ids = get_commnet_id('0', numtime2)
for user_id in user_ids:
follow_num = random.randint(1, 24)
if follow_num == 12:
auto_follow_list.append(user_id)
except:
logging_exception()
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()
import pymysql
import datetime
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'alpha',
'USER': 'work',
'PASSWORD': 'Gengmei123!',
'HOST': '172.21.36.16',
'PORT': '3306',
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4",
},
},
'master': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'alpha',
'USER': 'work',
'PASSWORD': 'Gengmei123!',
'HOST': '172.21.36.6',
'PORT': '3306',
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4",
},
},
'face': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'face',
'USER': 'work',
'PASSWORD': 'Gengmei123!',
'HOST': '172.21.36.16',
'PORT': '3306',
# 'CONN_MAX_AGE': None,
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4",
},
},
'commodity': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'commodity',
'USER': 'work',
'PASSWORD': 'Gengmei123!',
'HOST': '172.21.36.16',
'PORT': '3306',
# 'CONN_MAX_AGE': None,
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4",
},
}
}
host = DATABASES['default']['HOST']
user = DATABASES['default']['USER']
port = DATABASES['default']['PORT']
db = DATABASES['default']['NAME']
passwd = DATABASES['default']['PASSWORD']
def time_convs(numtime, numtime2):
'''
params: 1, 2
datetime.now(): 2019-10-09 10:35:50.231463
return: 2019-10-08 23:59:59.000000 2019-10-07 00:00:00.000000
'''
try:
now = datetime.datetime.now()
yes_time = now - datetime.timedelta(days=numtime)
yes_time_str = yes_time.strftime('%Y-%m-%d')
yes_time_str = yes_time_str + ' 23:59:59.000000'
yes_time2 = now - datetime.timedelta(days=numtime2)
yes_time_str2 = yes_time2.strftime('%Y-%m-%d')
yes_time_str2 = yes_time_str2 + ' 00:00:00.000000'
return yes_time_str, yes_time_str2
except:
return None
def get_commnet_id(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 create_time > '%s' and create_time < '%s' " % (numtime, numtime2))
data_new_user = cursor.fetchall()
all_data = list(data_new_user)
user_id_list = []
for i in all_data and all_data:
cursor.execute(
"select user_id from user_extra where user_id =" + str(i[0]) + " and is_shadow =0 ")
data = cursor.fetchall()
user_id = list(data)
if (user_id and user_id[0][1] == 0) or len(user_id) == 0:
user_id_list.append(i)
pc.close()
return user_id_list
# numtime1, numtime2 = time_convs(1, 1)
# user_id = get_commnet_id(numtime2, numtime1)
import asyncio
import time
async def say_after(delay):
await asyncio.sleep(delay)
print(delay)
return delay
async def main():
task_list = []
for i in range(10):
task_list.append(asyncio.create_task(say_after(i)))
for i in task_list:
await i
# task1 = asyncio.create_task(say_after(2, 'hello2'))
# task2 = asyncio.create_task(say_after(1, 'world2'))
# result3 = await task1
# result4 = await task2
# print(result3, result4)
# print(f"finished at {time.strftime('%X')}")
# 通过asyncio.run()函数运行
asyncio.run(main())
\ 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