m_func.py
3.6 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
#! /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/'
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
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