infotodb.py 文件源码

python
阅读 43 收藏 0 点赞 0 评论 0

项目:uicourses_v2 作者: sumerinlan 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号