def startNewAttendance(): if request.method == 'POST': attendance = Attendance(attendanceCollection) data = request.get_json() courseCode = data['courseCode'] date = helpers.getDate() attendanceExits = attendance.getAttendance(date, courseCode) attendanceExits = loads(attendanceExits) if (len(attendanceExits) > 0): res = jsonify('Attendace has already been taken for today') return res student = Students(studentCollection) students = student.getStudentsForParticleCourse(courseCode) stdAttendance = loads(students) for student in stdAttendance: student['present'] = False classAttendance = {'allStudents': stdAttendance, 'unknownStudents': []} obj = { 'courseCode': courseCode, 'date': date, 'classAttendance': classAttendance } att = attendance.addNewAttendance(obj) res = jsonify('New Attendance started.') return res
def getStudents(): if request.method == 'POST': student = Students(studentCollection) data = request.get_json() courseCode = data['courseCode'] students = student.getStudentsForParticleCourse(courseCode) studentsObj = loads(students) for student in studentsObj: student.pop('encodings') return dumps(studentsObj)
def main(): request = requests.get("https://hackbulgaria.com/api/students/") api_data = json.loads(request.text) students = Students() courses = Courses() for api_student in api_data: student_id = students.insert(api_student["name"], api_student["github"], api_student["available"]) for api_course in api_student["courses"]: course_id = courses.insert(api_course["name"]) students.assign_to_course(student_id, course_id, api_course["group"])
def index(): if request.method == 'POST': new_student = Students(request.form['first_name'], request.form['last_name']) students_list.append(new_student) return redirect(url_for('index')) return render_template('index.html', students=students_list)
def addNewStudent(): if request.method == 'POST': student = Students(studentCollection) data = request.get_json() name = data['name'] matricule = data['matricule'] email = data['email'] courses = data['courses'] faculty = data['faculty'] img_data = data['image'] path = f'api/images/{matricule}' helpers.base64toImg(img_data, path) encodings = helpers.getEncodings(path) string_ints = [str(int) for int in encodings] encodingsStr = ",".join(string_ints) url = firebase.uploadImage(path) obj = { 'name': name, 'photoUrl': url, 'matricule': matricule, 'email': email, 'encodings': encodingsStr, 'courses': courses, 'faculty': faculty } student.addNewStudent(obj) if os.path.exists(f'{path}.jpg'): os.remove(f'{path}.jpg') else: print("The file does not exist") res = jsonify('New student added succesfully') return res
def read_personal_data(self): self.file_name = self.check_input_filename() with open(self.file_name) as f: lines_all = f.readlines() try: data = [ Students(line.replace('\n', '').split('\t')) for line in lines_all ] self._student_credits_list = StudentCreditsList(data) print(self._student_credits_list) except Exception as e: print("Data file 을 읽다가 오류가 발생했습니다. [{0}]".format(e.__repr__()))
def students_page(): if request.method == 'POST': school_name = request.form.get('E or H school', '') new_student_name = request.form.get('name', '') new_student_id = request.form.get('id', '') new_student = Students(school_name=school_name, student_name=new_student_name, student_id=new_student_id) students.append(new_student) return redirect(url_for('students_page')) return render_template('index.html', students=students)
def main(): with Database('students.db', debug=True) as db: db.add_csv('students.csv', types=('TEXT', 'INT', 'INT PRIMARY KEY')) db.add_csv('courses.csv', types=('TEXT', 'INT', 'INT')) students = compute_student_averages(group_students(db)) # create_peeps_avg(db, students) # print_student_averages(students) with Students() as students: students.print_averages() print() for id in students.ids(): students.add_course(id, 'Soft-Dev' * id, 100) students.print_averages()
def add_a_new_entry(self): """ Add student info into the student list. """ id = self.input_id() name = self.input_name() birthday = self.input_birthday() midterm = self.input_score(1, 'Input Midterm Score') finalterm = self.input_score(1, 'Input Finalterm Score') self._student_credits_list.append( Students((0, id, name, birthday, midterm, finalterm))) self.attach_index() print(" Add function finished ")
def read_personal_data(self): """The function to read data file which is student credit data. Recreate "StudentCreditsList" from the file. Raises: Exception: While reading file has wrong. """ self._filename = self.input_filename() with open(self._filename, encoding='utf-8') as f: lines_all = f.readlines() try: for line in lines_all: self._student_credits_list.append(Students(line.split())) except Exception as e: print("Data file 을 읽다가 오류가 발생했습니다. [{0}]".format(e.__repr__())) self.attach_index() self.print_the_contents_of_all_entries()
def getstdsby_name(lastname): c.execute('SELECT * FROM student WHERE last=:last', {'last':lastname}) return c.fetchall() def update_std(std, marks): with conn: c.execute('UPDATE student SET marks = :marks WHERE first = :first AND last = :last', {'first':std.first, 'last':std.last, 'marks':marks}) def remove_std(std): with conn: c.execute('DELETE from student WHERE first = :first AND last = :last', {'first':std.first, 'last':std.last}) std_1 = Students('Jason', 'Fisher', 470) std_2 = Students('Fabiano', 'Fisher', 476) insert_std(std_1) insert_std(std_2) std = getstdsby_name('Fisher') print(std) update_std(std_2, 490) remove_std(std_1) std = getstdsby_name('Fisher') print(std) # c.execute('INSERT INTO student VALUES(:first, :last, :marks)', {"first":std_2.first, "last":std_2.last, "marks":std_2.marks}) # c.execute('SELECT * FROM student')
def on_edit_students_select(self): """Open the editing student window.""" edit_window = Students() edit_window.exec_()
# -*- coding: utf-8 -*- ''' 单继承: 有两个类,a类和b类,当a类继承自b类时,a类拥有了b类的所有属性 说明:继承者叫子类, 被继承者叫父类 object类是所有类的父类,还可以称为基类或者超类 注意:如果父类中有私有属性,在子类中是不能访问的,可以间接通过函数进行访问 ''' from students import Students from person import Person per = Person('tt', 1) stu1 = Students('jam', 20, '浙江理工') print stu1.school # 通过函数间接访问父类的私有属性 print stu1.getage() stu = Students('tom', 19, '哈弗大学') print stu.hobby('爬山') + '毕业于 %s' % stu.school
def add_user(first, last, expedient, mail): new_user = Students(first, last, expedient, mail) return new_user
from flask import Flask, jsonify, request from dotenv import load_dotenv from db_config import configure_database from students import Students load_dotenv() app = Flask(__name__) mysql = configure_database(app) student_db = Students(mysql) @app.before_first_request def create_table(): student_db.create_table() @app.route('/api/students/', methods=['POST', 'GET']) def students(): if request.method == 'POST': request_data = request.get_json() response = student_db.add_new_student(request_data) return jsonify(response) elif request.method == 'GET': response = student_db.get_all_students() return jsonify({'students': response})
for gid in groups.get_gid_list(): for stud in students.youngest(gid): print(stud) #reading from files try: with open("groups.obj","rb") as gfile: groups = pickle.load(gfile) except IOError: groups = Groups() try: with open("students.obj","rb") as sfile: students = pickle.load(sfile) except IOError: students = Students() #UI realisation commands = {11: add_g, 12: add_s, 21: remove_g, 22: remove_s, 31: list_g, 32: list_s, 4: filtr} while True: try: comm = str(input("\n1. Add\n2. Remove\n3. List\n4. Filter\n0. Done\nEnter command: ")) if comm == '1' or comm == '2': comm += str(input("\n1. Group\n2. Student\n0. Back\nEnter command: ")) if comm == '10' or comm == '20': continue elif comm == '3': comm += str(input("\n1. Groups\n2. Students\n0. Back\nEnter command: ")) if comm == '30': continue
elif sys.argv[1] == '-n' or sys.argv[1] == '--news': c = News() if len(sys.argv) == 2: pass elif len(sys.argv[2]) == 4: if len(sys.argv) == 4 and sys.argv[3] == '-v': # -n 2020 -v c.show_news_in_a_year(sys.argv[2], with_details=True) else: c.show_news_in_a_year(sys.argv[2]) elif len(sys.argv) == 5 and sys.argv[2] == '-t': # -n -t start end c.show_news_in_time_period(sys.argv[3], sys.argv[4]) elif len(sys.argv) == 6 and sys.argv[3] == '-t': # -n -v -t start end c.show_news_in_time_period(sys.argv[4], sys.argv[5], with_details=True) elif sys.argv[1] == '-s' or sys.argv[1] == '--student': c = Students() if len(sys.argv) == 3: c.show_students(sys.argv[2]) elif len(sys.argv) == 4 and (sys.argv[3][0] != '-'): # -s batch ia with_interests = False with_advisor = False for x in sys.argv[3]: if x == 'i': with_interests = True elif x == 'a': with_advisor = True c.show_students(sys.argv[2], with_interests, with_advisor) elif len(sys.argv) == 6 and (sys.argv[3][0] != '-'): # -f batch ia -[n, i, a] filter with_interests = False
return self._list == other def __ne__(self, other): return self._list != other def sort(self, key=None, reverse=False): self._list.sort(key=key, reverse=reverse) def insert(self, ii, val): pass def remove(self, ii): pass def append(self, val): pass def save(self, files): with open("./"+files, 'w') as datafile: datafile.write(self.__repr__()) if __name__=='__main__': with open("1.txt") as f: lines_all = f.readlines() foo = [ Students(line.replace('\n','').split('\t')) for line in lines_all] voo = StudentCreditsList(foo) for list_val in voo: list_val.mean = (list_val._midterm + list_val._finalterm)/2 dd = voo.sort( key=lambda x : (x._mean, x._name), reverse=True) print(voo)
def main(): courses = Courses() students = Students() teachers = Teachers() while True: print("\nMain Menu") print(f"{20 * '-'}") print("1. Manage Students") print("2. Manage Teachers") print("3. Manage Course") print("4. Exit") while True: choice = input("Pick one: ") if not choice.isdigit(): print("Give a number please") continue choice = int(choice) if choice < 1 or choice > 4: print("Index out of borders") else: break if choice == 1: while True: print("\nManage Students") print(f"{20 * '-'}") print("1. Create Student") print("2. Add Course to Students") print("3. Read Students") print("4. Update Students") print("5. Delete Students") print("6. Back to Main Menu") while True: manage_student_choice = input("Pick one: ") if not manage_student_choice.isdigit(): print("Give a number please") continue manage_student_choice = int(manage_student_choice) if manage_student_choice < 1 or manage_student_choice > 6: print("Index out of borders") else: break if manage_student_choice == 1: # CREATE STUDENT print("\nINSERT STUDENT") print(f"{20 * '-'}") create_student(students) elif manage_student_choice == 2: # ADD COURSE TO STUDENT print("\nADD COURSE TO STUDENT") print(f"{20 * '-'}") add_course_to_student(students, courses) elif manage_student_choice == 3: # READ STUDENTS while True: print("\nREAD STUDENTS") print(f"{20 * '-'}") print("1. Read a student id") print("2. Read all students") print("3. Back to Students Menu") while True: read_students_choice = input("Pick one: ") if not read_students_choice.isdigit(): print("Give a number please") continue read_students_choice = int(read_students_choice) if read_students_choice < 1 or read_students_choice > 3: print("Index out of borders") else: break if read_students_choice == 1: # READ STUDENT BY ID student_id = input("Give student id: ") student = students.find_by_id(student_id) if student is None: print(f"There is no student with id {student_id}") else: print(student) elif read_students_choice == 2: # READ ALL STUDENTS for student in students.students: print(student) print(f"{20 * '='}") elif read_students_choice == 3: # BACK TO STUDENTS MENU break elif manage_student_choice == 4: # UPDATE STUDENTS print("\nUPDATE STUDENTS") print(f"{20 * '-'}") update_student(students) elif manage_student_choice == 5: # DELETE STUDENTS print("\nDELETE STUDENTS") print(f"{20 * '-'}") delete_student(students) elif manage_student_choice == 6: # BACK TO MAIN MENU break elif choice == 2: while True: print("\nManage Teachers") print(f"{20 * '-'}") print("1. Create Teacher") print("2. Add Course to Teacher") print("3. Read Teachers") print("4. Update Teachers") print("5. Delete Teachers") print("6. Back to Main Menu") while True: manage_teacher_choice = input("Pick one: ") if not manage_teacher_choice.isdigit(): print("Give a number please") continue manage_teacher_choice = int(manage_teacher_choice) if manage_teacher_choice < 1 or manage_teacher_choice > 6: print("Index out of borders") else: break if manage_teacher_choice == 1: # CREATE TEACHER print("\nINSERT ΤΕΑCHER") print(f"{20 * '-'}") insert_teacher(teachers) elif manage_teacher_choice == 2: # ADD COURSE TO TEACHER print("\nADD COURSE TO TEACHER") print(f"{20 * '-'}") add_course_to_teacher(teachers, courses) elif manage_teacher_choice == 3: # READ TEACHER while True: print("\nREAD TEACHERS") print(f"{20 * '-'}") print("1. Read a teacher by id") print("2. Read all teachers") print("3. Back to Teachers Menu") while True: read_teachers_choice = input("Pick one: ") if not read_teachers_choice.isdigit(): print("Give a number please") continue read_teachers_choice = int(read_teachers_choice) if read_teachers_choice < 1 or read_teachers_choice > 3: print("Index out of borders") else: break if read_teachers_choice == 1: # READ TEACHER BY ID teacher_id = input("Give teacher id: ") teacher = teachers.find_by_id(teacher_id) if teacher is None: print(f"There is no student with id {teacher_id}") else: print(teacher) elif read_teachers_choice == 2: # READ ALL TEACHERS for teacher in teachers.teachers: print(teacher) print(f"{20 * '='}") elif read_teachers_choice == 3: # BACK TO STUDENTS MENU break elif manage_teacher_choice == 4: # UPDATE TEACHER print("\nUPDATE TEACHER") print(f"{20 * '-'}") update_teacher(teachers) elif manage_teacher_choice == 5: # DELETE TEACHER print("\nDELETE TEACHER") print(f"{20 * '-'}") delete_teacher(teachers) elif manage_teacher_choice == 6: # BACK TO MAIN MENU break elif choice == 3: while True: print("\nManage Course") print(f"{20 * '-'}") print("1. Create Course") print("2. Read Courses") print("3. Update Course") print("4. Delete Course") print("5. Back to Main Menu") while True: manage_course_choice = input("Pick one: ") if not manage_course_choice.isdigit(): print("Give a number please") continue manage_course_choice = int(manage_course_choice) if choice < 1 or choice > 5: print("Index out of borders") else: break if manage_course_choice == 1: print("\nCREATE COURSE") print(f"{20 * '-'}") create_course(courses) elif manage_course_choice == 2: while True: print("\nREAD COURSES") print(f"{20 * '-'}") print("1. Read a course by id") print("2. Read a course by title") print("3. Read all courses") print("4. Back to Courses Menu") while True: read_courses_choice = input("Pick one: ") if not read_courses_choice.isdigit(): print("Give a number please") continue read_courses_choice = int(read_courses_choice) if choice < 1 or choice > 4: print("Index out of borders") else: break if read_courses_choice == 1: # read course by id course_id = input("Give course id: ") course = courses.find_by_id(course_id) if course is None: print(f"There is no course with id {course_id}") else: print(course) elif read_courses_choice == 2: # Read course by title course_title = input("Give course title: ") course = courses.find_by_title(course_title) if course is None: print(f"There is no course with title {course_title}") else: print(course) elif read_courses_choice == 3: # Read all courses print("University Courses") print(f"{20 * '-'}") courses.print_courses() elif read_courses_choice == 4: # Go back to courses menu break elif manage_course_choice == 3: # UPDATE COURSE print("\nUPDATE COURSE") print(f"{20 * '-'}") update_course(courses) elif manage_course_choice == 4: # DELETE COURSE print("\nDELETE COURSE") print(f"{20 * '-'}") delete_course(courses) elif manage_course_choice == 5: break elif choice == 4: courses.store_to_file() teachers.store_to_file() students.store_to_file() print("Bye bye") break
def main(): course = Courses() students = Students() finish_operation = False while not finish_operation: print(""" Welcome To EDUCEMY What would you like to do 1. View Courses 2. Enroll in course 3. Display all students 4. Display student information 5. Update Student Information 6. Delete Student Information 7. Complete course for student 8. Clear Display 9. Exit Application """) main_prompt = input('What would you like to do?') if main_prompt == '1': course.display_details() elif main_prompt == '2': students.enroll_student() elif main_prompt == '3': students.display_all_student_details() elif main_prompt == '4': students.display_student_information() elif main_prompt == '5': students.update_student_information() elif main_prompt == '6': students.delete_student_information() elif main_prompt == '7': students.complete_course() elif main_prompt == '8': Functions.clear() elif main_prompt == '9': sys.exit() else: print(f"""ERROR:\nInput must be in range 1-7""") continue finish_prompt = input('Would you like to perform more operations?(y/n)') if finish_prompt in ['n', 'N']: finish_operation = True Functions.clear() print(""" Thank You for Visiting EDUCEMY. Have a good day """)
"""remove item in the list """ self._list.remove(ii) def append(self, val): """Append item into the list """ self._list.append(val) def save(self, files): """ Save a studentCreditsList class """ with open("./" + files, 'w', encoding='utf-8') as datafile: datafile.write(self.__repr__()) if __name__ == '__main__': with open("data.txt", encoding='utf-8') as f: lines_all = f.readlines() foo = [Students(line.split()) for line in lines_all] voo = StudentCreditsList(foo) print(voo) voo.sort(key=lambda x: (x.mean, x.name), reverse=True) print(voo) voo.append(Students((16, '11111111', 'e', '2000-01-01', 30, 34))) print(voo) students = (filter(lambda item: item._id == '11111111', voo)) for student in students: voo.remove(student) print(voo)