You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
981 B

# t_university_zhiye_tree
import json
from Util import MysqlUtil
def insertTable(code, name):
sql = "insert into t_university_zhiye_tree(ZhiYeCode,ZhiYeName) values(%s,%s)"
db.execute(sql, (code, name))
db.commit()
if __name__ == '__main__':
# 初始化连接
with open("Config.json", 'r') as load_f:
connect = json.load(load_f)
db = MysqlUtil.MySQLConnect(connect)
# 清表
sql = 'truncate table t_university_zhiye_tree'
db.execute(sql)
db.commit()
with open("ZhiYe.json", 'r', encoding='utf-8') as load_f:
jo = json.load(load_f)
for j in jo['result']:
# 插入数据
insertTable(j['code'], j['name'])
children = j['children']
for k in children:
insertTable(k['code'], k['name'])
jobs = k['jobs']
for p in jobs:
insertTable(p['code'], p['name'])
# # 关闭数据库
db.close()