import xlrd
from xlutils.copy import copy
import requests
import json
host='http://##authCodeLogin'
payload={"phone":"15210546986","authCode":"123456"}
s=json.dumps(payload)
header = {
'Content-Type':'application/json;charset=UTF-8'
}
r =requests.post(host,data=s,headers=header)
print(r.content)
print(r.json()['retValue']['token'])
print('登录')
host1='http://##gotoapp'
payload1={"appOpenId":"","organizationId":97966,"organizationName":"小精灵","roleId":690,"roleName":"销售经理","tenantId":50002218,"dataScope":1,"userId":1278890,"userCode":"","nickName":"韩2"}
s=json.dumps(payload1)
header1 = {
'Content-Type':'application/json;charset=UTF-8',
'Authorization':"Bearer "+str(r.json()['retValue']['token'])
}#'Bearer ' + str(a)
r1 =requests.post(host1,data=s,headers=header1)
print(r1.content)
print('获取身份')
host1='http://##/gotoapp'
payload1={"appOpenId":"","organizationId":97966,"organizationName":"小精灵","roleId":690,"roleName":"销售经理","tenantId":50002218,"dataScope":1,"userId":1278890,"userCode":"","nickName":"韩2"}
s=json.dumps(payload1)
header1 = {
'Content-Type':'application/json;charset=UTF-8',
'Authorization':"Bearer "+str(r.json()['retValue']['token'])
}#'Bearer ' + str(a)
r1 =requests.post(host1,data=s,headers=header1)
print(r1.content)
print('&&&&0814&&&&&')
old_excel = xlrd.open_workbook('L1.xlsx')
sheet = old_excel.sheets()[0]
url_3 = 'http://##/save'
headers_3 = {
'Content-Type':'application/json;charset=UTF-8',
'Authorization':"Bearer "+str(r.json()['retValue']['token'])
}
i = 0
new_excel = copy(old_excel)
for row in sheet.get_rows():
data_3 = row[0].value
# s_3=json.dumps(data_3)
print(data_3)
response_3 = requests.post(url=url_3, headers=headers_3, data=data_3)
text = response_3.text
print(response_3.content)
#使用json.loads可以把Unicode类型,即json类型转换成dict类型
# text = json.loads(text)["returnMsg"] #屏蔽这行代码即可把返回的完整数据写入文件中
ws = new_excel.get_sheet(0)
# ws.write(i,1,text)
# new_excel.save('L1.xlsx')
old_excel = xlrd.open_workbook('L1.xlsx')
new_excel = copy(old_excel)
i = i+1