-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonparser.py
33 lines (30 loc) · 1.04 KB
/
jsonparser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json
import os
import peewee
from model import db, CourseData, GradeData
JSON_FILE = "/Users/splitline/course-data/1071.json"
data = json.load(open(JSON_FILE))
db.connect()
db.create_tables([CourseData, GradeData])
for course in data:
try:
grade_data = GradeData.select().where(
GradeData.semester == course['Semester'],
(GradeData.course_no == course['CourseNo']) |
(GradeData.course_no == course['CourseNo'][:-1])
)
CourseData.create(
semester=course['Semester'],
course_no=course['CourseNo'],
course_name=course['CourseName'],
credit=course['CreditPoint'],
node=course['Node'],
dimension=course['Dimension'] if course['Dimension'] != "" and course['Dimension'] != "無" else None,
lecturer=course['CourseTeacher'],
grade_data=grade_data.get() if grade_data.exists() else None
)
except peewee.IntegrityError as e:
pass
# print(course)
# print(e)
db.close()