Commit 691d1d3e authored by lixiaofang's avatar lixiaofang

add sleep_time

parent a67a9c25
This diff is collapsed.
......@@ -138,7 +138,9 @@ if __name__ == "__main__":
for i in user_id:
if i[0] not in dict.keys():
dict.setdefault(i[0], [])
dict[i[0]].append(i[1])
else:
......@@ -154,7 +156,7 @@ if __name__ == "__main__":
for i in range(urge_num):
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cook=logins()
......
import requests
import time
import datetime
import pymysql
import random
import traceback
from log_settings import *
import logging
auto_click_url = "http://earth.igengmei.com/api/v1/like"
login_url = "http://earth.igengmei.com/api/account/login_pwd"
def index_first():
try:
r1 = requests.get(login_url)
return r1.cookies.get_dict()
except:
logging.error("index_first:%s" % traceback.format_exc())
return None
def get_majia():
try:
data = open("batch_user_gen")
list=[]
for i in data:
list.append(i.strip('\n').strip(','))
maj = random.randint(1,len(list))
user_id=list[maj-1]
return user_id
except:
logging.error("catch exception,get_majia:%s" % traceback.format_exc())
return None
def get_cookies(user_id):
try:
with open("user_session.txt", 'r') as f:
try:
data = f.readlines()
except:
data = None
list = []
for i in data:
list.append(i.strip('\n').split(","))
for i in list:
if user_id == i[0]:
return (i[1])
except:
return None
def login():
try:
user_id=get_majia()
cookies = get_cookies(user_id)
if cookies is not None:
return {'sessionid': cookies}
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
return None
def click(cookies_get, id):
try:
post_dict = {
'type': 0,
'id': id
}
response = requests.post(url=auto_click_url,
cookies=cookies_get,
data=post_dict)
logging.info("response.text:%s" % response.text)
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
def time_conv(numtime):
try:
now = datetime.datetime.now()
yes_time = now - datetime.timedelta(days=numtime)
yes_time_str = yes_time.strftime('%Y-%m-%d')
return yes_time_str
except:
return None
def get_data(numtime):
try:
db = pymysql.connect(host="rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com", user='work', passwd='Gengmei123',
db="alpha", port=3306)
cursor = db.cursor()
cursor.execute("SELECT user_id,id FROM topic WHERE is_online=1 and create_time LIKE '%%%%%s%%%%'" % numtime)
data = cursor.fetchall()
user_id = list(data)
logging.info("Database version : %s " % user_id)
db.close()
return user_id
except:
logging.error("catch exception,get_data:%s" % traceback.format_exc())
return None
if __name__ == "__main__":
try:
time_list = [1,2,3,4,5,6,7]
for i in time_list:
numtime = time_conv(i)
user_id = get_data(numtime)
dict = {}
for i in user_id:
if i[0] not in dict.keys():
dict.setdefault(i[0], [])
dict[i[0]].append(i[1])
else:
dict[i[0]].append(i[1])
for key,value in dict.items():
rand_num = random.randint(0,len(value)-1)
rand_id = value[rand_num]
urge_num = random.randint(0, 1)
for i in range(urge_num):
time.sleep(random.randint(10, 50))
cook=login()
if cook is not None:
click(cook, rand_id)
except:
logging.error("catch exception,main:%s" % traceback.format_exc())
......@@ -148,7 +148,7 @@ if __name__ == "__main__":
for i in topic_id:
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cook = logins()
......
......@@ -142,7 +142,7 @@ if __name__ == "__main__":
for i in range(follow_num):
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cookies=logins()
......
......@@ -147,8 +147,6 @@ if __name__ == "__main__":
for i in value:
# time.sleep(random.randint(10, 50))
cookies=logins(id)
if cookies is not None:
......
......@@ -188,7 +188,7 @@ if __name__ == "__main__":
for i in range(follow_num):
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cookies = logins()
......
......@@ -134,7 +134,7 @@ if __name__ == "__main__":
cookies = index_first()
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cook=logins()
......
......@@ -133,7 +133,7 @@ if __name__ == "__main__":
for i in range(urge_num):
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cook=logins()
......
......@@ -198,7 +198,7 @@ if __name__ == "__main__":
for i in range(urge_num):
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cookies = logins()
......
......@@ -143,7 +143,7 @@ if __name__ == "__main__":
for i in range(1):
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cookies = logins()
......
......@@ -179,7 +179,7 @@ if __name__ == "__main__":
for i in range(1):
# time.sleep(random.randint(10, 50))
time.sleep(random.randint(10, 50))
cookies = logins()
......
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