def setCourses(stdscr): courses = [] f = open("courses.txt", "a") for i in range(getInputNum("courses", stdscr)): stdscr.addstr("\nCourse " + str(i + 1) + ":") course = Course(stdscr) courses.append(course) f.write(course.toString() + '\n') f.close() return courses
def list_course(screen , course): # TODO screen.addstr("Enter number of course:\n - ") course_number = int(screen.getstr().decode()) course["number"] = course_number for i in range(course_number): screen.addstr("Enter course name:\n - ") course_name = screen.getstr().decode() screen.addstr("Enter course id:\n - ") course_id = int(screen.getstr().decode()) screen.addstr("Enter course credit:\n - ") course_credit = int(screen.getstr().decode()) x = Course(course_name, course_id, course_credit, []) course["courses"].append(x.addCourse())
def setCourses(stdscr): courses = [] for i in range(getInputNum("courses", stdscr)): stdscr.addstr("\nCourse " + str(i + 1) + ":") course = Course(stdscr) courses.append(course) return courses
def main(stdscr): students = [] courses = [] current_row = 0 curses.curs_set(0) curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) if os.path.exists('students.pickle'): with open('students.pickle', 'rb') as file: students_in_file = pickle.load(file) for student in students_in_file: students.append(student) courses_in_file = pickle.load(file) for course in courses_in_file: courses.append(course) else: file = open('students.pickle', 'wb') print_menu(stdscr, current_row) while 1: key = stdscr.getch() stdscr.clear() thread = BackgroundThread('students.pickle', stdscr) thread.start() thread.add_objects(students, courses) if key == curses.KEY_UP and current_row > 0: current_row -= 1 elif key == curses.KEY_DOWN and current_row < len(menu): current_row += 1 elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 0: stdscr.clear() curses.echo() std_number = std_num(stdscr) for i in range(std_number): stdscr.clear() stdscr.addstr(0, 0, f"- Student number {i + 1} info is: ") stdscr.addstr(2, 0, " + Student name: ") student_name = stdscr.getstr(3, 0).decode() stdscr.addstr(4, 0, ' + Student DoB: ') dob = stdscr.getstr(5, 0).decode() students.append(Student(student_name, dob)) stdscr.refresh() with open("student.txt", "w") as sf: for student in students: sf.write( f"{student.get_id()} : {student.get_name()} : {student.get_dob()} \n" ) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 1: stdscr.clear() curses.echo() course_number = course_num(stdscr) for i in range(course_number): stdscr.addstr(0, 0, f"- Course number {i + 1} info is: ") stdscr.addstr(1, 0, f" + Course {i + 1} name: ") course_name = stdscr.getstr(2, 0).decode() stdscr.addstr(3, 0, f" + Course {i + 1} credit: ") course_credit = stdscr.getstr(4, 0).decode() courses.append(Course(course_name, course_credit)) stdscr.refresh() with open("course.txt", "w") as cf: for course in courses: cf.write( f"{course.get_id()}: {course.get_name()} with {course.get_credit()} credit \n" ) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 2: stdscr.clear() curses.echo() stdscr.addstr(0, 0, "- Which course do you want to add marks") course_name = stdscr.getstr(1, 0).decode() course_index = contain_course(course_name, courses) if course_index < 0: stdscr.addstr(2, 0, "This course does not exist") else: courses[course_index].set_mark(students, stdscr) with open("mark.txt", "w") as mf: mf.write(f"{course_name} \n") for name, mark in courses[course_index].get_mark().items(): mf.write(f"{name} : {mark} \n") mf.write("\n") stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 3: stdscr.clear() curses.echo() show_students(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 4: stdscr.clear() curses.echo() show_course(courses, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 5: stdscr.clear() curses.echo() show_gpa(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 6: thread.join() file.close() break print_menu(stdscr, current_row)
def Init(class_student, course): mylines = [] with open('info/marks.txt', 'rt') as myfile: for myline in myfile: mylines.append(myline.rstrip('\n')) i = 1 mul = 0 ID = [] Name = [] courses = [] GPA = [] for line in mylines: if i == 2 + mul * 5: ID.append(line[4:]) elif i == 3 + mul * 5: Name.append(line[6:]) elif i == 4 + mul * 5: courses.append(line[8:]) elif i == 5 + mul * 5: GPA.append(line[5:]) if i % 5 == 0: mul = mul + 1 i = i + 1 DoB = [] with open('info/students.txt', 'rt') as myfile: for line in myfile: if line.find("DoB") == 0: DoB.append(line.rstrip('\n')) for i in range(len(ID)): stu = Student(Name[i], int(ID[i]), DoB[i][5:], [], float(GPA[i])) class_student["students"].append(stu.getStudent()) #TODO #extract function t = [] for c in range(0, len(courses)): list = [] a = 0 for i in courses[c].split("]"): if a == 0 and len(i) > 1: list.append(i[2:]) elif len(i) > 1: list.append(i[3:]) a = a + 1 for i in range(len(list)): t = t + list[i].split(", ") for i in range(0, len(t), 3): t[i] = t[i].rstrip(string.punctuation).lstrip(string.punctuation) t[i + 1] = int(t[i + 1]) t[i + 2] = int(t[i + 2]) count = len(t)/6 #TODO #after i got x start to fill in wait needed #Remember that thi student course now is still not in a correct form id = 1 for i in range(0,len(t),3): x = Course(str(t[i]), int(id), int(t[i+2]), []) id = id + 1 course["courses"].append(x.addCourse()) #TODO count = count - 1 if count == 0: break #Add mark time ind = 0 for student in class_student["students"]: for num in range(0,2): student["_course"].append([t[ind], t[ind+1], t[ind+2]]) ind = ind + 3 #TODO: add marks to course cor = 0 for i in range(len(class_student["students"])): for m in range(len(course["courses"])): #TODO course["courses"][m]["_course_mark"].append([class_student["students"][i]["_name"], class_student["students"][i]["_course"][m][1]]) # for cour in course["courses"]: # print("ID: " + str(cour["_course_id"]) + " --- Name: " + cour["_course_name"] + "\n") # print("Credit: " + str(cour["_course_credit"]) + "\n") # for mark in cour["_course_mark"]: # print(str(mark) + "\n") #doneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee # print(class_student) # for a in class_student["students"]: # print(a) # print(course) # if __name__ == '__main__': # Init()
def main(stdscr): students = [] courses = [] current_row = 0 curses.curs_set(0) curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) print_menu(stdscr, current_row) while 1: key = stdscr.getch() stdscr.clear() if key == curses.KEY_UP and current_row > 0: current_row -= 1 elif key == curses.KEY_DOWN and current_row < len(menu): current_row += 1 elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 0: stdscr.clear() curses.echo() std_number = std_num(stdscr) for i in range(std_number): stdscr.clear() stdscr.addstr(0, 0, f"- Student number {i + 1} info is: ") stdscr.addstr(2, 0, " + Student name: ") student_name = stdscr.getstr(3, 0).decode() stdscr.addstr(4, 0, ' + Student DoB: ') dob = stdscr.getstr(5, 0).decode() students.append(Student(student_name, dob)) stdscr.refresh() stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 1: stdscr.clear() curses.echo() course_number = course_num(stdscr) for i in range(course_number): stdscr.addstr(0, 0, f"- Course number {i + 1} info is: ") stdscr.addstr(1, 0, f" + Course {i + 1} name: ") course_name = stdscr.getstr(2, 0).decode() stdscr.addstr(3, 0, f" + Course {i + 1} credit: ") course_credit = stdscr.getstr(4, 0).decode() courses.append(Course(course_name, course_credit)) stdscr.refresh() stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 2: stdscr.clear() curses.echo() stdscr.addstr(0, 0, "- Which course do you want to add marks") course_name = stdscr.getstr(1, 0).decode() course_index = contain_course(course_name, courses) if course_index < 0: stdscr.addstr(2, 0, "This course does not exist") else: courses[course_index].set_mark(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 3: stdscr.clear() curses.echo() show_students(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 4: stdscr.clear() curses.echo() show_course(courses, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 5: stdscr.clear() curses.echo() show_gpa(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 6: break print_menu(stdscr, current_row)