login_func.py
7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Date: 2020/4/9 11:36
# @Author:bxh
# @file: login_func.py
import json
import time,datetime
path = 'E:/task_api/'
def teardown_hook_sleep_N_secs(response,n_secs):
""" sleep n seconds after request """
if response.status_code == 200:
time.sleep(0.3)
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:
jsondata = json.loads(response.text)
serialno =str(jsondata['data']['question']['serialNo'])
try:
with open(path + 'config/serialNo.csv','w+') as f:
f.write(serialno)
print('写入成功,serialno:{}'.format(serialno))
f.close()
except Exception as e:
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:
jsondata = json.loads(response.text)
access_token =jsondata['data']['accessToken']
try:
# 保存token到文件
with open(path + 'config/task_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_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:
accesstoken = f.read()
print('读取成功,accesstoken:{}'.format(accesstoken))
except Exception as e:
print('读取失败', e)
accesstoken = str(accesstoken)
return accesstoken
def get_serialNo():
try:
with open(path + "config/serialNo.csv", 'r') as f:
serialno = f.read()
print('读取成功,serialno:{}'.format(serialno))
except Exception as e:
print('读取失败', e)
serialno = str(serialno)
return serialno
def get_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():
try:
with open(path + "config/credentials.csv", 'r') as f:
credentials = f.read()
print('读取成功,credentials:{}'.format(credentials))
except Exception as e:
print('读取失败', e)
credentials = str(credentials)
return credentials
def get_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():
try:
with open(path + "config/cid.csv", 'r') as f:
cid = f.read()
print('读取成功,muid:{}'.format(cid))
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")
return bidEndTime
def teardown_hook_get_credentials(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
credentials =str(jsondata['data']['credentials'])
try:
with open(path + 'config/credentials.csv','w+') as f:
f.write(credentials)
print('写入成功,credentials:{}'.format(credentials))
f.close()
except Exception as e:
print('写入失败', e)
return credentials
def teardown_hook_get_muid(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
muid =str(jsondata['data']['companys'][0]['muid'])
try:
with open(path + 'config/muid.csv','w+') as f:
f.write(muid)
print('写入成功,muid:{}'.format(muid))
f.close()
except Exception as e:
print('写入失败', e)
return muid
def teardown_hook_get_cid(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
cid =str(jsondata['data']['companys'][0]['cid'])
try:
with open(path + 'config/cid.csv','w+') as f:
f.write(cid)
print('写入成功,muid:{}'.format(cid))
f.close()
except Exception as e:
print('写入失败', e)
return cid