def get_group_id_by_faculty_name(faculty_name): db = get_db_connect() cursor = get_cursor(db) answer = [] query = str("SELECT * FROM {} WHERE `faculty` = '{}'") \ .format(constants.table_faculty, faculty_name) data = cursor.execute(query) faculties = tools.data_to_list_class(data, "faculty") lessons = get_lessons() for faculty in faculties: if str(faculty.faculty) == faculty_name: for lesson in lessons: if str(lesson.group_id) == str(faculty.group_id): answer.append(faculty.group_id) break if faculties: close_connection(cursor, db) return answer else: close_connection(cursor, db) return None
def get_events(): db = get_db_connect() cursor = get_cursor(db) query = "SELECT * FROM {0}".format(constants.table_events) data = cursor.execute(query) events = tools.data_to_list_class(data, "event") close_connection(cursor, db) return events
def get_lessons_by_week(group_id, week): db = get_db_connect() cursor = get_cursor(db) query = "SELECT * FROM {0} WHERE `week` = '{1}' AND `group_id` = '{2}'".format( constants.table_lessons, week, group_id) data = cursor.execute(query) lessons = tools.data_to_list_class(data, "lesson") close_connection(cursor, db) return lessons
def get_lessons(db_name=None): if db_name: db = get_db_connect(db_name) else: db = get_db_connect() cursor = get_cursor(db) query = "SELECT * FROM {0}".format(constants.table_lessons) data = cursor.execute(query) lessons = tools.data_to_list_class(data, "lesson") close_connection(cursor, db) return lessons
def get_sessions(db_name=None): if db_name: db = get_db_connect(db_name) else: db = get_db_connect() cursor = get_cursor(db) query = "SELECT * FROM {0}".format(constants.table_session) data = cursor.execute(query) if data: session_list = tools.data_to_list_class(data, to_class="session") close_connection(cursor, db) return session_list else: close_connection(cursor, db) return None
def get_qualification_list_by_group_id(group_id, db_name=None): if db_name: db = get_db_connect(db_name) else: db = get_db_connect() cursor = get_cursor(db) query = "SELECT * FROM {0} WHERE `group_id` = '{1}'".format( constants.table_qualification, group_id) data = cursor.execute(query) if data: session_list = tools.data_to_list_class(data, to_class="qualification") close_connection(cursor, db) return session_list else: close_connection(cursor, db) return None
def get_faculties(db_name=None): if db_name: db = get_db_connect(db_name) else: db = get_db_connect() cursor = get_cursor(db) query = "SELECT * FROM {0}".format(constants.table_faculty) data = cursor.execute(query) if data: faculties = tools.data_to_list_class(data, "faculty") close_connection(cursor, db) return faculties else: close_connection(cursor, db) return None
def get_lessons_by_day_name(day_name, week, group_id): db = get_db_connect() cursor = get_cursor(db) query = str("SELECT * FROM {0} WHERE `day_name` = '{day_name}' AND `week` = '{week}' AND `group_id` = '{group}'")\ .format(constants.table_lessons, day_name=day_name, group=group_id, week=week) data = cursor.execute(query) lessons = tools.data_to_list_class(data, "lesson") if lessons: close_connection(cursor, db) return lessons else: close_connection(cursor, db) return None