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

fix

parent 93377de8
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)
......@@ -14,24 +14,30 @@ def get_commnet_id(numtime, numtime2):
# 发贴后
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' " % (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)
def auto_follow(time_start, time_end, num_low, num_top, num_one=None):
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()
if cookies is not None:
follow(cookies, user_id)
except:
pass
logging.info("Database version : %s " % user_id_list)
pc.close()
return user_id_list
def auto_follow_per_1d_by_post():
......@@ -40,43 +46,40 @@ def auto_follow_per_1d_by_post():
# 0-3星
# 1天前发的帖子:[2-6]个粉丝
numtime1, numtime2 = time_convs(1, 1)
user_id = get_commnet_id(numtime2, numtime1, )
user_ids = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
for user_id in user_ids:
follow_num = random.randint(2, 6)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
follow(cookies, user_id)
except:
pass
# 2-15天前发的帖子:[0-1]个粉丝
numtime1, numtime2 = time_convs(2, 15)
user_id = get_commnet_id(numtime2, numtime1)
user_ids = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
for user_id in user_ids:
follow_num = random.randint(0, 1)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
follow(cookies, user_id)
except:
pass
# 15天前或更早发的帖子:每隔11天[0-2]个粉丝
numtime1, numtime2 = time_convs(2, 15)
user_id = get_commnet_id('0', numtime2)
user_ids = get_commnet_id('0', numtime2)
try:
for j in user_id and user_id:
id = int(j[0])
for user_id in user_ids:
follow_num = random.randint(1, 6)
if follow_num == 6:
cookies = login()
if cookies is not None:
follow(cookies, id)
follow(cookies, user_id)
except:
pass
......@@ -84,43 +87,40 @@ def auto_follow_per_1d_by_post():
# 4-6星
# 1天前发的帖子:[5-10]个粉丝
numtime1, numtime2 = time_convs(1, 1)
user_id = get_commnet_id(numtime2, numtime1)
user_ids = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
for user_id in user_ids:
follow_num = random.randint(5, 10)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
follow(cookies, user_id)
except:
pass
# 2-15天前发的帖子:[0-5]个粉丝
numtime1, numtime2 = time_convs(2, 15)
user_id = get_commnet_id(numtime2, numtime1)
user_ids = get_commnet_id(numtime2, numtime1)
try:
for j in user_id and user_id:
id = int(j[0])
for user_id in user_ids:
follow_num = random.randint(0, 5)
for i in range(follow_num):
cookies = login()
if cookies is not None:
follow(cookies, id)
follow(cookies, user_id)
except:
pass
# 15天前或更早发的帖子:每隔11天[0-2]个粉丝
numtime1, numtime2 = time_convs(2, 15)
user_id = get_commnet_id('0', numtime2)
user_ids = get_commnet_id('0', numtime2)
try:
for j in user_id and user_id:
id = int(j[0])
for user_id in user_ids:
follow_num = random.randint(1, 6)
if follow_num == 6:
cookies = login()
if cookies is not None:
follow(cookies, id)
follow(cookies, user_id)
except:
pass
......
......@@ -26,7 +26,7 @@ def get_commnet_id(numtime, numtime2):
"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:
if len(user_id) == 0:
user_id_list.append(i)
logging.info("Database version : %s " % user_id_list)
......
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