ticket-py/yes24/generateConfigFile.py
2024-04-30 17:47:01 +08:00

37 lines
1.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding:utf-8 -*-
import xlrd
import json
usersFile="Users.xlsx"
wb=xlrd.open_workbook(filename=usersFile)
sheet=wb.sheet_by_index(0)
rows=sheet.nrows
if rows==0:
print("excel文件错误请检查")
exit()
print("共有{}行用户信息".format(rows))
i=0
rList=[]
while i<rows:
print("获取用户名{}密码{}".format(sheet.cell(i,0).value,sheet.cell(i,1).value))
user={}
user['userName']=sheet.row(i)[0].value.strip()
user['userPwd']=sheet.row(i)[1].value.strip()
if len(sheet.row(i))>2:
user['idCustomer']=sheet.row(i)[2].value.strip()
else:
user['idCustomer']=""
rList.append(user)
if (i+1)%7==0:
print("生成最终用户信息文件config/users{}.json".format(i+1))
with open('config/users{}.json'.format(i+1),'w') as f:
json.dump(rList,f)
rList=[]
i+=1
#刚好是奇数位结尾
if len(rList)>0:
print("生成最终用户信息文件config/users{}.json".format(i+1))
with open('config/users{}.json'.format(i+1),'w') as f:
json.dump(rList,f)