Files
jupyter/体测单位/海淀老干部大学.ipynb
T
2025-03-04 13:23:52 +08:00

3.8 KiB

体测人员导入

In [7]:
import openpyxl
import json
from datetime import date

wb = openpyxl.load_workbook('data/海淀老干部局第一期.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}

for n in range(3, sheet.max_row+1):
    code = int(sheet.cell(n, 1).value)
    person.setdefault(code, {})
    dict1 = {}
    dict1['name'] = sheet.cell(n, 2).value
    dict1['sex'] = sheet.cell(n, 3).value
    dict1['unit'] = '第一期'
    dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0]
    dict1['id'] = sheet.cell(n, 5).value
    if sheet.cell(n,6).value is not None:
        dict1['phone'] = str(sheet.cell(n,6).value) 
    person[code] = dict1
filename = 'data/海淀区老干部大学第一期.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False)
print(len(person))
print('ok')
49
ok

生成读卡系统文件

In [6]:
import json

filename = 'data/海淀区老干部大学第一期.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
list1 = []
for k, v in dict1.items():
    dict2 = {}
    #if dict1['sex'] =='男':
    #    sex = 1
    
    dict2 = {'id':k,'name':v['name'],'gender':v['sex'],'birth':v['birth'],'unit':v['unit']}
    list1.append(dict2)
json_data = json.dumps(list1,ensure_ascii=False, indent=4)  

# 将 json 数据写入文件
with open("data/card_海淀区老干部大学.json", "w",encoding = 'utf-8') as file:
    file.write(json_data)   
print('ok')
ok
In [ ]: