Ejemplo n.º 1
0
def listsubject():
    connect = sqlite3.connect('information.db')
    subjects = connect.execute(
        'SELECT course.courseID, course.courseName, course.schoolYear FROM course INNER JOIN courseDetails ON course.courseID=courseDetails.courseID GROUP BY course.courseID;'
    )
    for subject in subjects:
        course = Course(subject[0], subject[1])
        for class_num, classroom, limitation, teacher in connect.execute(
                'SELECT courseDetails.class, courseDetails.classroom, courseDetails.limitation, courseDetails.teacher FROM course INNER JOIN courseDetails ON course.courseID=courseDetails.courseID WHERE course.courseID=? GROUP BY courseDetails.class;',
            (subject[0], )).fetchall():
            course.add_class_num(class_num, subject[0], subject[1])
            course.add_classroom(subject[0], subject[1], class_num - 1,
                                 classroom)
            course.add_limitation(subject[0], subject[1], class_num - 1,
                                  limitation)
            course.add_teacher(subject[0], subject[1], class_num - 1, teacher)
            dates_and_times = connect.execute(
                'SELECT courseDetails.day, courseDetails.month, courseDetails.year, courseDetails.startHour, courseDetails.startMinute, courseDetails.endHour, courseDetails.endMinute FROM course INNER JOIN courseDetails ON course.courseID=courseDetails.courseID WHERE courseDetails.class=?;',
                (class_num, ))
            for date_and_time in dates_and_times:
                course.add_datetime(
                    subject[0], subject[1], class_num - 1,
                    datetime(date_and_time[2], date_and_time[1],
                             date_and_time[0]),
                    time(date_and_time[3], date_and_time[4]),
                    time(date_and_time[5], date_and_time[6]))
        course_list.add_course(course.get_course())
    connect.commit()
    connect.close()
    return jsonify(course_list.get_list())
Ejemplo n.º 2
0
from datetime import datetime, time
import sqlite3

course_list = CourseList()
connect = sqlite3.connect('information.db')
subjects = connect.execute(
    'SELECT course.courseID, course.courseName, course.schoolYear FROM course INNER JOIN courseDetails ON course.courseID=courseDetails.courseID GROUP BY course.courseID;'
)
for subject in subjects:
    course = Course(subject[0], subject[1])
    for class_num, classroom, limitation, teacher in connect.execute(
            'SELECT courseDetails.class, courseDetails.classroom, courseDetails.limitation, courseDetails.teacher FROM course INNER JOIN courseDetails ON course.courseID=courseDetails.courseID WHERE course.courseID=? GROUP BY courseDetails.class;',
        (subject[0], )).fetchall():
        course.add_class_num(class_num, subject[0], subject[1])
        course.add_classroom(subject[0], subject[1], class_num - 1, classroom)
        course.add_limitation(subject[0], subject[1], class_num - 1,
                              limitation)
        course.add_teacher(subject[0], subject[1], class_num - 1, teacher)
        dates_and_times = connect.execute(
            'SELECT courseDetails.day, courseDetails.month, courseDetails.year, courseDetails.startHour, courseDetails.startMinute, courseDetails.endHour, courseDetails.endMinute FROM course INNER JOIN courseDetails ON course.courseID=courseDetails.courseID WHERE courseDetails.class=?;',
            (class_num, ))
        for date_and_time in dates_and_times:
            course.add_datetime(
                subject[0], subject[1], class_num - 1,
                datetime(date_and_time[2], date_and_time[1], date_and_time[0]),
                time(date_and_time[3], date_and_time[4]),
                time(date_and_time[5], date_and_time[6]))
    course_list.add_course(course.get_course())
print(course_list.get_list())
connect.commit()
connect.close()