...
|
...
|
@@ -3,10 +3,10 @@ |
|
|
# Date: 2020/4/9 11:36
|
|
|
# @Author:bxh
|
|
|
# @file: login_func.py
|
|
|
import json
|
|
|
import time,datetime
|
|
|
path = 'E:/task_api/'
|
|
|
# path = 'E:/mmm_auto/task_api/'
|
|
|
import json
|
|
|
import time, datetime
|
|
|
|
|
|
|
|
|
def teardown_hook_sleep_N_secs(response,n_secs):
|
|
|
""" sleep n seconds after request """
|
|
|
if response.status_code == 200:
|
...
|
...
|
@@ -14,20 +14,6 @@ def teardown_hook_sleep_N_secs(response,n_secs): |
|
|
else:
|
|
|
time.sleep(n_secs)
|
|
|
|
|
|
def teardown_hook_get_cuid(response):
|
|
|
if response.status_code == 200:
|
|
|
jsondata = json.loads(response.text)
|
|
|
cuid =str(jsondata['data']['cuid'])
|
|
|
|
|
|
try:
|
|
|
|
|
|
with open(path + 'config/cuid.csv','w+') as f:
|
|
|
f.write(cuid)
|
|
|
print('写入成功,cuid:{}'.format(cuid))
|
|
|
f.close()
|
|
|
except Exception as e:
|
|
|
print('写入失败', e)
|
|
|
return cuid
|
|
|
|
|
|
def teardown_hook_get_serialNo(response):
|
|
|
if response.status_code == 200:
|
...
|
...
|
@@ -36,7 +22,7 @@ def teardown_hook_get_serialNo(response): |
|
|
|
|
|
try:
|
|
|
|
|
|
with open(path + 'config/serialNo.txt','w+') as f:
|
|
|
with open('config/serialNo.txt','w+') as f:
|
|
|
f.write(serialno)
|
|
|
print('写入成功,serialno:{}'.format(serialno))
|
|
|
f.close()
|
...
|
...
|
@@ -44,19 +30,6 @@ def teardown_hook_get_serialNo(response): |
|
|
print('写入失败', e)
|
|
|
return serialno
|
|
|
|
|
|
def teardown_hook_get_accesstoken(response):
|
|
|
if response.status_code == 200:
|
|
|
jsondata = json.loads(response.text)
|
|
|
access_token =jsondata['data']['accessToken']
|
|
|
try:
|
|
|
# 保存token到文件
|
|
|
with open(path + 'config/accessToken.csv','w+') as f:
|
|
|
f.write(access_token)
|
|
|
print('写入成功,access_token:{}'.format(access_token))
|
|
|
f.close()
|
|
|
except Exception as e:
|
|
|
print('写入失败', e)
|
|
|
return access_token
|
|
|
|
|
|
def teardown_hook_get_task_accesstoken(response):
|
|
|
if response.status_code == 200:
|
...
|
...
|
@@ -64,7 +37,7 @@ def teardown_hook_get_task_accesstoken(response): |
|
|
access_token =jsondata['data']['accessToken']
|
|
|
try:
|
|
|
# 保存token到文件
|
|
|
with open(path + 'config/task_accessToken.csv','w+') as f:
|
|
|
with open('config/task_accessToken.csv','w+') as f:
|
|
|
f.write(access_token)
|
|
|
print('写入成功,access_token:{}'.format(access_token))
|
|
|
f.close()
|
...
|
...
|
@@ -72,67 +45,11 @@ def teardown_hook_get_task_accesstoken(response): |
|
|
print('写入失败', e)
|
|
|
return access_token
|
|
|
|
|
|
def teardown_hook_get_authcode(response):
|
|
|
if response.status_code ==200:
|
|
|
jsondata = json.loads(response.text)
|
|
|
auth_code = jsondata['data']['authCode']
|
|
|
try:
|
|
|
|
|
|
with open(path + "config/authCode.csv", 'w+') as f:
|
|
|
f.write(auth_code)
|
|
|
print('写入成功,authCode:{}'.format(auth_code))
|
|
|
except Exception as e:
|
|
|
print('写入失败', e)
|
|
|
return auth_code
|
|
|
|
|
|
def teardown_hook_get_task_authcode(response):
|
|
|
if response.status_code ==200:
|
|
|
jsondata = json.loads(response.text)
|
|
|
auth_code = jsondata['data']['authCode']
|
|
|
try:
|
|
|
|
|
|
with open(path + "config/task_authCode.csv", 'w+') as f:
|
|
|
f.write(auth_code)
|
|
|
print('写入成功,authCode:{}'.format(auth_code))
|
|
|
except Exception as e:
|
|
|
print('写入失败', e)
|
|
|
return auth_code
|
|
|
|
|
|
def get_authcode():
|
|
|
try:
|
|
|
with open(path + "config/authCode.csv", 'r') as f:
|
|
|
auth_code = f.read()
|
|
|
print('读取成功,authCode:{}'.format(auth_code))
|
|
|
except Exception as e:
|
|
|
print('读取失败', e)
|
|
|
auth_code = str(auth_code)
|
|
|
return auth_code
|
|
|
|
|
|
def get_task_authcode():
|
|
|
try:
|
|
|
with open(path + "config/task_authCode.csv", 'r') as f:
|
|
|
auth_code = f.read()
|
|
|
print('读取成功,authCode:{}'.format(auth_code))
|
|
|
except Exception as e:
|
|
|
print('读取失败', e)
|
|
|
auth_code = str(auth_code)
|
|
|
return auth_code
|
|
|
|
|
|
def get_accesstoken():
|
|
|
try:
|
|
|
# 保存token到文件
|
|
|
with open(path + "config/accessToken.csv", 'r') as f:
|
|
|
accesstoken = f.read()
|
|
|
print('读取成功,accesstoken:{}'.format(accesstoken))
|
|
|
except Exception as e:
|
|
|
print('读取失败', e)
|
|
|
accesstoken = str(accesstoken)
|
|
|
return accesstoken
|
|
|
|
|
|
def get_task_accesstoken():
|
|
|
try:
|
|
|
# 保存token到文件
|
|
|
with open(path + "config/task_accessToken.csv", 'r') as f:
|
|
|
with open("config/task_accessToken.csv", 'r') as f:
|
|
|
accesstoken = f.read()
|
|
|
print('读取成功,accesstoken:{}'.format(accesstoken))
|
|
|
except Exception as e:
|
...
|
...
|
@@ -140,124 +57,71 @@ def get_task_accesstoken(): |
|
|
accesstoken = str(accesstoken)
|
|
|
return accesstoken
|
|
|
|
|
|
def get_serialNo():
|
|
|
try:
|
|
|
with open(path + "config/serialNo.txt", 'r') as f:
|
|
|
serialno = f.read()
|
|
|
print('读取成功,serialno:{}'.format(serialno))
|
|
|
except Exception as e:
|
|
|
print('读取失败', e)
|
|
|
serialno = str(serialno)
|
|
|
return serialno
|
|
|
|
|
|
def get_cuid():
|
|
|
global cuid
|
|
|
cuid = ''
|
|
|
try:
|
|
|
with open(path + "config/cuid.csv", 'r') as f:
|
|
|
cuid = f.read()
|
|
|
print('读取成功,cuid:{}'.format(cuid))
|
|
|
except Exception as e:
|
|
|
print('读取失败', e)
|
|
|
cuid = str(cuid)
|
|
|
return cuid
|
|
|
|
|
|
def get_credentials():
|
|
|
global credentials
|
|
|
credentials = ''
|
|
|
def teardown_hook_get_task_manager_accesstoken(response):
|
|
|
if response.status_code == 200:
|
|
|
jsondata = json.loads(response.text)
|
|
|
access_token =jsondata['data']['access']['accessToken']
|
|
|
try:
|
|
|
with open(path + "config/credentials.csv", 'r') as f:
|
|
|
credentials = f.read()
|
|
|
print('读取成功,credentials:{}'.format(credentials))
|
|
|
# 保存token到文件
|
|
|
with open('config/task_manager_accessToken.csv','w+') as f:
|
|
|
f.write(access_token)
|
|
|
print('写入成功,access_token:{}'.format(access_token))
|
|
|
f.close()
|
|
|
except Exception as e:
|
|
|
print('读取失败', e)
|
|
|
# credentials = str(credentials)
|
|
|
return credentials
|
|
|
print('写入失败', e)
|
|
|
return access_token
|
|
|
|
|
|
def get_muid():
|
|
|
global muid
|
|
|
muid = ''
|
|
|
try:
|
|
|
with open(path + "config/muid.csv", 'r') as f:
|
|
|
muid = f.read()
|
|
|
print('读取成功,muid:{}'.format(muid))
|
|
|
except Exception as e:
|
|
|
print('读取失败', e)
|
|
|
muid = str(muid)
|
|
|
return muid
|
|
|
|
|
|
def get_cid():
|
|
|
global cid
|
|
|
cid = ''
|
|
|
def get_task_manager_accesstoken():
|
|
|
try:
|
|
|
with open(path + "config/cid.csv", 'r') as f:
|
|
|
cid = f.read()
|
|
|
print('读取成功,muid:{}'.format(cid))
|
|
|
# 保存token到文件
|
|
|
with open("config/task_manager_accessToken.csv", 'r') as f:
|
|
|
accesstoken = f.read()
|
|
|
print('读取成功,accesstoken:{}'.format(accesstoken))
|
|
|
except Exception as e:
|
|
|
print('读取失败', e)
|
|
|
cid = str(cid)
|
|
|
return cid
|
|
|
|
|
|
t =datetime.datetime.now()
|
|
|
def get_bidStartTime():
|
|
|
#当前日期
|
|
|
t1 = t.strftime('%Y-%m-%d 00:00:00')
|
|
|
# #转为秒级时间戳
|
|
|
# bidStartTime = time.mktime(time.strptime(t1, '%Y-%m-%d %H:%M:%S'))
|
|
|
# #转为毫秒级
|
|
|
# bidStartTime = str(bidStartTime*1000).split(".")[0]
|
|
|
return t1
|
|
|
|
|
|
def get_bidEndTime():
|
|
|
# 1天后
|
|
|
bidEndTime = (t + datetime.timedelta(days=1)).strftime("%Y-%m-%d 00:00:00")
|
|
|
accesstoken = str(accesstoken)
|
|
|
return accesstoken
|
|
|
|
|
|
return bidEndTime
|
|
|
|
|
|
def teardown_hook_get_credentials(response):
|
|
|
def teardown_hook_get_authcode(response):
|
|
|
if response.status_code == 200:
|
|
|
jsondata = json.loads(response.text)
|
|
|
credentials =str(jsondata['data']['credentials'])
|
|
|
|
|
|
auth_code = jsondata['data']['authCode']
|
|
|
try:
|
|
|
|
|
|
with open(path + 'config/credentials.csv','w+') as f:
|
|
|
f.write(credentials)
|
|
|
print('写入成功,credentials:{}'.format(credentials))
|
|
|
# 保存token到文件
|
|
|
with open('config/authCode.csv','w') as f:
|
|
|
f.write(auth_code)
|
|
|
print('写入成功,authCode:{}'.format(auth_code))
|
|
|
f.close()
|
|
|
except Exception as e:
|
|
|
print('写入失败', e)
|
|
|
return credentials
|
|
|
return auth_code
|
|
|
|
|
|
def teardown_hook_get_muid(response):
|
|
|
if response.status_code == 200:
|
|
|
jsondata = json.loads(response.text)
|
|
|
muid =str(jsondata['data']['companys'][0]['muid'])
|
|
|
|
|
|
def get_authcode():
|
|
|
try:
|
|
|
|
|
|
with open(path + 'config/muid.csv','w+') as f:
|
|
|
f.write(muid)
|
|
|
print('写入成功,muid:{}'.format(muid))
|
|
|
with open('config/authCode.csv','r') as f:
|
|
|
authcode_value = f.read()
|
|
|
print('读取authcode_value成功:{}'.format(authcode_value))
|
|
|
f.close()
|
|
|
except Exception as e:
|
|
|
print('写入失败', e)
|
|
|
return muid
|
|
|
print('读取失败', e)
|
|
|
authcode_value = str(authcode_value)
|
|
|
return authcode_value
|
|
|
|
|
|
def teardown_hook_get_cid(response):
|
|
|
if response.status_code == 200:
|
|
|
jsondata = json.loads(response.text)
|
|
|
cid =str(jsondata['data']['companys'][0]['cid'])
|
|
|
|
|
|
def get_serialNo():
|
|
|
try:
|
|
|
|
|
|
with open(path + 'config/cid.csv','w+') as f:
|
|
|
f.write(cid)
|
|
|
print('写入成功,muid:{}'.format(cid))
|
|
|
f.close()
|
|
|
with open("config/serialNo.txt", 'r') as f:
|
|
|
serialno = f.read()
|
|
|
print('读取成功,serialno:{}'.format(serialno))
|
|
|
except Exception as e:
|
|
|
print('写入失败', e)
|
|
|
return cid
|
|
|
print('读取失败', e)
|
|
|
serialno = str(serialno)
|
|
|
return serialno
|
|
|
|
|
|
#————————————————————————————————————————————————————————————————————————————————————————————————————————————
|
|
|
#引用资源模块
|
|
|
def teardown_hook_get_resource_id(response):
|
...
|
...
|
@@ -267,7 +131,7 @@ def teardown_hook_get_resource_id(response): |
|
|
jsondata = json.loads(response.text)
|
|
|
resource_id = str(jsondata['data']['list'][0]['id'])
|
|
|
try:
|
|
|
with open(path + "config/resource_id.txt", 'w+') as f:
|
|
|
with open("config/resource_id.txt", 'w+') as f:
|
|
|
f.write(resource_id)
|
|
|
print('写入成功,resource_id:{}'.format(resource_id))
|
|
|
except Exception as e:
|
...
|
...
|
@@ -278,7 +142,7 @@ def get_resource_id(): |
|
|
global resource_id
|
|
|
resource_id =''
|
|
|
try:
|
|
|
with open(path + "config/resource_id.txt", 'r') as f:
|
|
|
with open("config/resource_id.txt", 'r') as f:
|
|
|
resource_id = f.read()
|
|
|
print('读取成功,resource_id:{}'.format(resource_id))
|
|
|
except Exception as e:
|
...
|
...
|
@@ -297,7 +161,7 @@ def teardown_hook_get_resource_title(response): |
|
|
resource_title = jsondata['data']['list'][0]['title']
|
|
|
try:
|
|
|
|
|
|
with open(path + "config/resource_title.txt", 'w+') as f:
|
|
|
with open("config/resource_title.txt", 'w+') as f:
|
|
|
f.write(resource_title)
|
|
|
print('写入成功,resource_title:{}'.format(resource_title))
|
|
|
except Exception as e:
|
...
|
...
|
@@ -308,7 +172,7 @@ def get_resource_title(): |
|
|
global resource_title
|
|
|
resource_title = ''
|
|
|
try:
|
|
|
with open(path + "config/resource_title.txt", 'r') as f:
|
|
|
with open("config/resource_title.txt", 'r') as f:
|
|
|
resource_title = f.read()
|
|
|
print('读取成功,resource_id:{}'.format(resource_title))
|
|
|
except Exception as e:
|
...
|
...
|
@@ -324,7 +188,7 @@ def teardown_hook_get_resource_content(response): |
|
|
resource_content = jsondata['data']['list'][0]['content']
|
|
|
try:
|
|
|
|
|
|
with open(path + "config/resource_content.txt", 'w+') as f:
|
|
|
with open("config/resource_content.txt", 'w+') as f:
|
|
|
f.write(resource_content)
|
|
|
print('写入成功,authCode:{}'.format(resource_content))
|
|
|
except Exception as e:
|
...
|
...
|
@@ -335,7 +199,7 @@ def get_resource_content(): |
|
|
global resource_content
|
|
|
resource_content = ''
|
|
|
try:
|
|
|
with open(path + "config/resource_content.txt", 'r') as f:
|
|
|
with open("config/resource_content.txt", 'r') as f:
|
|
|
resource_content = f.read()
|
|
|
print('读取成功,resource_content:{}'.format(resource_content))
|
|
|
except Exception as e:
|
...
|
...
|
|