def info_to_db(db, name):
cur = db.cursor()
with open(name) as data_file:
data = json.load(data_file)
subject = data['subject']
code = data['code']
title = data['title']
credit = data['credit']
desc = data['desc']
geneds = data['geneds']
if geneds is None:
geneds = ''
else:
geneds = ','.join(geneds)
url = data['url']
cmd = 'INSERT INTO `CourseExplorer` (`Id`, `Subject`, `Code`, `Title`, `Credit`, `Description`, `GenEd`, ' \
'`Url`) VALUES(NULL, %s, %s, %s, %s, %s, %s, %s) '
val = (subject, code, title, credit, desc, geneds, url)
cur.execute(cmd, val)
# if subject == 'PHYS':
# print cmd % val
评论列表
文章目录