Commit 1ffd3535 authored by lixiaofang's avatar lixiaofang

try except

parent 98283ef0
This diff is collapsed.
......@@ -172,6 +172,7 @@ def get_new_user_id(numtime):
return None
def get_star_useid(numtime):
try:
db = pymysql.connect(host="rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com", user='work', passwd='Gengmei123',
......@@ -220,9 +221,9 @@ if __name__ == "__main__":
# time.sleep(random.randint(500, 1000))
#star
for i in time_list:
for i in range(len(time_list)):
numtime = time_conv(i)
numtime = time_conv(time_list[i])
user_id = get_star_useid(numtime)
......@@ -242,17 +243,16 @@ if __name__ == "__main__":
# time.sleep(random.randint(500, 1000))
for i in time_list:
for i in range(len(time_list)):
if i == 1:
if time_list[i] == 1:
numtime = time_conv(1)
numtime = time_conv(time_list[i])
topic_user_id = get_data(numtime)
new_user_id=get_new_user_id(numtime)
for i in new_user_id:
for j in topic_user_id:
......
import requests
import time
import datetime
import pymysql
import random
import traceback
from log_settings import *
import logging
auto_pick_url = "http://earth.igengmei.com/api/v1/pick/do_pick"
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(','))
# time.sleep(random.randint(0, 500))
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 login():
try:
# time.sleep(random.randint(300, 500))
user_id=get_majia()
cookies = index_first()
post_dict={
'account_type':2,
'pwd':'123456',
'email':user_id
}
response = requests.post(
url=login_url,
data=post_dict,
cookies=cookies
)
headers=response.headers
cook = headers['Set-Cookie'].split(";")
cook = cook[0].split('=')[1]
logging.info("response.text :%s" % response.text)
return {'sessionid': cook}
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
return None
def logins(id):
try:
cookies = index_first()
post_dict={
'account_type':2,
'pwd':'123456',
'email':id
}
response = requests.post(
url=login_url,
data=post_dict,
cookies=cookies
)
headers=response.headers
cook = headers['Set-Cookie'].split(";")
cook = cook[0].split('=')[1]
logging.info("response.text :%s" % response.text)
return {'sessionid': cook}
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
return None
def pick(cookies_get,id):
try:
post_dict = {
'pick_user_id': id,
'is_pick': 1,
'pick_type': 0
}
response = requests.post(url=auto_pick_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 distinct(user_id) FROM topic WHERE 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
def get_new_user_id(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 from account_user WHERE is_online =1 and create_time LIKE '%%%%%s%%%%'" % numtime)
data_new_user = cursor.fetchall()
data = list(data_new_user)
logging.info("Database version : %s " % data)
db.close()
return user_id
except:
logging.error("catch exception,get_data:%s" % traceback.format_exc())
return None
def get_star_useid(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 FROM topic WHERE is_online =1 and content_level =4 or content_level =5 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]
#star
for i in range(len(time_list)):
numtime = time_conv(time_list[i])
user_id = get_star_useid(numtime)
for j in user_id:
id = int(j[0])
# time.sleep(random.randint(200,500))
pick_num=random.randint(1,5)
for i in range(pick_num):
cookies = login()
pick(cookies, id)
# time.sleep(random.randint(500, 1000))
for i in range(len(time_list)):
if time_list[i] == 1:
numtime = time_conv(time_list[i])
topic_user_id = get_data(numtime)
new_user_id=get_new_user_id(numtime)
for i in new_user_id:
for j in topic_user_id:
if i == j :
pick_num = random.randint(0,1)
for x in range(pick_num):
cookies = logins(id)
pick(cookies, i)
except:
logging.error("catch exception,main:%s" % traceback.format_exc())
import requests
import time
import datetime
import pymysql
import random
import pandas as pd
import traceback
from log_settings import *
import logging
auto_urge_url = "http://earth.igengmei.com/api/v1/user/urge"
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(','))
# time.sleep(random.randint(0, 500))
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 logins():
try:
# time.sleep(random.randint(300, 500))
user_id=get_majia()
cookies = index_first()
post_dict={
'account_type':2,
'pwd':'123456',
'email':user_id
}
response = requests.post(
url=login_url,
data=post_dict,
cookies=cookies
)
headers=response.headers
cook = headers['Set-Cookie'].split(";")
cook = cook[0].split('=')[1]
logging.info("response.text :%s" % response.text)
return {'sessionid': cook}
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
return None
def Urge(cookies_get, id):
try:
post_dict = {
'id': id
}
response = requests.post(url=auto_urge_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_star_useid(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 FROM topic WHERE is_online=1 and content_level =4 or content_level =5 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_star_useid(numtime)
for j in user_id:
id = int(j[0])
# time.sleep(random.randint(200,500))
for i in range(1):
cookies = logins()
Urge(cookies, id)
# time.sleep(random.randint(500, 1000))
except:
logging.error("catch exception,main:%s" % traceback.format_exc())
\ No newline at end of file
x=(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (695,), (696,), (695,), (698,), (699,), (700,), (695,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (709,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (678,), (None,), (709,), (709,), (709,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (732,), (730,), (729,), (None,), (173,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,)
for i in range(3):
print(i)
for i in x:
for i in range(3):
print(i)
if i[0] is not None:
print(i[0])
\ No newline at end of file
for i in range(3):
print(i)
\ 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