m_func.py
10.9 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Date: 2020/5/28 23:13
# @Author:bxh
# @file: usiness_admin_func.py
import json
from urllib.parse import *
path = 'E:/task_api/'
# path = 'E:/mmm_auto/task_api/'
def teardown_hook_get_Authorization(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
Authorization =jsondata['data']['access']['token']
try:
# 保存token到文件
with open(path + 'config/Authorization.txt','w+') as f:
f.write(Authorization)
print('写入成功,Authorization:{}'.format(Authorization))
f.close()
except Exception as e:
print('写入失败', e)
return Authorization
def teardown_hook_get_task_Authorization(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
Authorization =jsondata['data']['access']['accessToken']
try:
# 保存token到文件
with open(path + 'config/task_Authorization.txt','w+') as f:
f.write(Authorization)
print('写入成功,Authorization:{}'.format(Authorization))
f.close()
except Exception as e:
print('写入失败', e)
return Authorization
def teardown_hook_get_access_token(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
access_token =jsondata['data']['access']['token']
try:
# 保存token到文件
with open(path + 'config/access_token.txt','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_login_code(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
login_code =jsondata['data']['list'][2]['url']
res = login_code.split("=")[1].rstrip('"')
res = unquote(res)
try:
# 保存token到文件
with open(path + 'config/login_code.txt','w+') as f:
f.write(res)
print('写入成功,res:{}'.format(res))
f.close()
except Exception as e:
print('写入失败', e)
return res
#写入抢单任务id
def teardown_hook_get_loot_task_id(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
task_id =jsondata['data']['id']
try:
# 保存token到文件
with open(path + 'config/loot_task_id.txt','w+') as f:
f.write(task_id)
print('写入成功,task_id:{}'.format(task_id))
f.close()
except Exception as e:
print('写入失败', e)
return task_id
#获取抢单任务id
def get_loot_task_id():
try:
# 保存token到文件
with open(path + "config/loot_task_id.txt", 'r') as f:
task_id = f.read()
print('读取成功,task_id:{}'.format(task_id))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return task_id
#写入竞标任务id
def teardown_hook_get_bid_task_id(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
task_id =jsondata['data']['id']
try:
# 保存token到文件
with open(path + 'config/bid_task_id.txt','w+') as f:
f.write(task_id)
print('写入成功,task_id:{}'.format(task_id))
f.close()
except Exception as e:
print('写入失败', e)
return task_id
#获取竞标任务id
def get_bid_task_id():
try:
# 保存token到文件
with open(path + "config/bid_task_id.txt", 'r') as f:
task_id = f.read()
print('读取成功,task_id:{}'.format(task_id))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return task_id
#写入指派任务id
def teardown_hook_get_appoint_task_id(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
task_id =jsondata['data']['id']
try:
# 保存token到文件
with open(path + 'config/appoint_task_id.txt','w+') as f:
f.write(task_id)
print('写入成功,task_id:{}'.format(task_id))
f.close()
except Exception as e:
print('写入失败', e)
return task_id
#第一次写入进行中的数据
def teardown_hook_get_task_3_1_total(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
task_total =str(len(jsondata['data']['tasks']))
try:
with open(path + 'config/task_3_total.txt','w+') as f:
f.write(task_total)
print('写入成功,task_total:{}'.format(task_total))
f.close()
except Exception as e:
print('写入失败', e)
return task_total
#第二次写入进行中的数据
def teardown_hook_get_task_3_2_total(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
task_total =str(len(jsondata['data']['tasks']))
try:
with open(path + 'config/task_3_2_total.txt','w+') as f:
f.write(task_total)
print('写入成功,task_total:{}'.format(task_total))
f.close()
except Exception as e:
print('写入失败', e)
return task_total
#第一次获取进行中的数据
def get_task_3_total():
try:
# 保存token到文件
with open(path + "config/task_3_total.txt", 'r') as f:
task_total = f.read()
print('读取成功,task_total:{}'.format(task_total))
except Exception as e:
print('读取失败', e)
return task_total
#第二次获取进行中的数据
def get_task_3_2_total():
try:
# 保存token到文件
with open(path + "config/task_3_2_total.txt", 'r') as f:
task_total = f.read()
print('读取成功,task_total:{}'.format(task_total))
except Exception as e:
print('读取失败', e)
return task_total
#获取指派任务id
def get_appoint_task_id():
try:
# 保存token到文件
with open(path + "config/appoint_task_id.txt", 'r') as f:
task_id = f.read()
print('读取成功,task_id:{}'.format(task_id))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return task_id
def get_Authorization():
try:
# 保存token到文件
with open(path + "config/Authorization.txt", 'r') as f:
Authorization = f.read()
print('读取成功,Authorization:{}'.format(Authorization))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return Authorization
def get_task_Authorization():
try:
# 保存token到文件
with open(path + "config/task_Authorization.txt", 'r') as f:
Authorization = f.read()
print('读取成功,Authorization:{}'.format(Authorization))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return Authorization
def get_access_token():
try:
# 保存token到文件
with open(path + "config/access_token.txt", 'r') as f:
access_token = f.read()
print('读取成功,access_token:{}'.format(access_token))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return access_token
def get_login_code():
try:
# 保存token到文件
with open(path + "config/login_code.txt", 'r') as f:
login_code = f.read()
print('读取成功,access_token:{}'.format(login_code))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return login_code
#----------------------------获取公共用户id-------------------------
def teardown_hook_get_uid0(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
uid0 =jsondata['data']['list'][0]['uid']
try:
# 保存token到文件
with open(path + 'config/uid0.txt','w+') as f:
f.write(uid0)
print('写入成功,uid0:{}'.format(uid0))
f.close()
except Exception as e:
print('写入失败', e)
return uid0
def get_uid0():
try:
# 保存token到文件
with open(path + "config/uid0.txt", 'r') as f:
uid0 = f.read()
print('读取成功,uid0:{}'.format(uid0))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return uid0
def teardown_hook_get_uid1(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
uid1 =jsondata['data']['list'][1]['uid']
try:
# 保存token到文件
with open(path + 'config/uid1.txt','w+') as f:
f.write(uid1)
print('写入成功,uid1:{}'.format(uid1))
f.close()
except Exception as e:
print('写入失败', e)
return uid1
def get_uid1():
try:
# 保存token到文件
with open(path + "config/uid1.txt", 'r') as f:
uid1 = f.read()
print('读取成功,uid1:{}'.format(uid1))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return uid1
def teardown_hook_get_uid2(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
uid2 = jsondata['data']['list'][2]['uid']
try:
# 保存token到文件
with open(path + 'config/uid2.txt','w+') as f:
f.write(uid2)
print('写入成功,uid2:{}'.format(uid2))
f.close()
except Exception as e:
print('写入失败', e)
return uid2
def get_uid2():
try:
# 保存token到文件
with open(path + "config/uid2.txt", 'r') as f:
uid2 = f.read()
print('读取成功,uid2:{}'.format(uid2))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return uid2
def teardown_hook_get_uid15(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
uid15 =jsondata['data']['list'][15]['uid']
try:
# 保存token到文件
with open(path + 'config/uid15.txt','w+') as f:
f.write(uid15)
print('写入成功,uid15:{}'.format(uid15))
f.close()
except Exception as e:
print('写入失败', e)
return uid15
def get_uid15():
try:
# 保存token到文件
with open(path + "config/uid15.txt", 'r') as f:
uid15 = f.read()
uid15 = int(uid15)
print('读取成功,uid15:{}'.format(uid15))
except Exception as e:
print('读取失败', e)
# Authorization = str(Authorization)
return uid15