login_func.py
5.2 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
# @Time :2019/11/26 11:23
# @Author :dengyuting
# @File :login_func.py
import json
import os
def teardown_hook_get_access_id(response):
os.remove('config/id.csv')
if response.status_code == 200:
jsondata = json.loads(response.text)
id =jsondata['data']['list']
try:
for i in range(len(id)):
a1 = str(id[i]['id'])
with open('config/id.csv','a+') as f:
f.writelines(a1 + '\n')
print('写入成功,id:{}'.format(a1))
except Exception as e:
print('写入失败', e)
return a1
#
# def get_id():
# try:
# with open('config/id.csv','r+') as f:
# id1 = f.read()
# print('读取id成功:{}'.format(id))
# f.close()
# except Exception as e:
# print('读取失败', e)
# # id = str(id1)
# return id
# # print(get_id())
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('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_m_accesstoken(response):
print(response.status_code)
if response.status_code == 200:
jsondata = json.loads(response.text)
access_token = jsondata['data']['access']['accessToken']
try:
# 保存token到文件
with open('config/m_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_refreshtoken(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
refresh_token =jsondata['data']['refreshToken']
try:
# 保存token到文件
with open('config/refreshToken.csv','w+') as f:
f.write(refresh_token)
print('写入成功,refresh_token:{}'.format(refresh_token))
f.close()
except Exception as e:
print('写入失败', e)
return refresh_token
def teardown_hook_get_m_refreshtoken(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
m_refresh_token =jsondata['data']['access']['refresh_token']
try:
# 保存token到文件
with open('config/m_refresh_token.csv','w+') as f:
f.write(m_refresh_token)
print('写入成功,m_refresh_token:{}'.format(m_refresh_token))
f.close()
except Exception as e:
print('写入失败', e)
return m_refresh_token
def teardown_hook_get_authcode(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
authCode = jsondata['data']['authCode']
try:
# 保存token到文件
with open('config/authCode.csv','w+') as f:
f.write(authCode)
print('写入成功,authCode:{}'.format(authCode))
f.close()
except Exception as e:
print('写入失败', e)
return authCode
def get_accesstoken():
try:
with open('config/accessToken.csv','r') as f:
accseetoken_value = f.read()
print('读取accseetoken_value成功:{}'.format(accseetoken_value))
f.close()
except Exception as e:
print('读取失败', e)
accseetoken_value = str(accseetoken_value)
return accseetoken_value
def get_m_accesstoken():
try:
with open('config/m_accessToken.csv','r') as f:
accseetoken_value = f.read()
print('读取accseetoken_value成功:{}'.format(accseetoken_value))
f.close()
except Exception as e:
print('读取失败', e)
accseetoken_value = str(accseetoken_value)
authorization = 'bearer ' + accseetoken_value
return authorization
def get_m_refreshtoken():
try:
with open('config/m_refresh_token.csv','r') as f:
m_refreshtoken_value = f.read()
print('读取m_refreshtoken_value成功:{}'.format(m_refreshtoken_value))
f.close()
except Exception as e:
print('读取失败', e)
m_refreshtoken_value = str(m_refreshtoken_value)
authorization = 'bear ' + m_refreshtoken_value
return authorization
def get_refreshtoken():
try:
with open('config/refreshToken.csv','r') as f:
refreshtoken_value = f.read()
print('读取refreshtoken_value成功:{}'.format(refreshtoken_value))
f.close()
except Exception as e:
print('读取失败', e)
refreshtoken_value = str(refreshtoken_value)
return refreshtoken_value
def get_authcode():
try:
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)
authcode_value = str(authcode_value)
return authcode_value