def drawtimetable(self, courselist=courselist, taken=courses.copy(), term=1, skip=[]): print "Term %d:" % term if term in skip: skip.remove(term) print "SKIP\n" drawtimetable(courselist, taken, term=term + 1) else: takencopy = {} i = 0 while i < len(courselist): #print taken course = courselist[i] courseinstance = Course(course) courseinstance.loadterm() currentterm = 1 if term % 2 else 2 if courseinstance.meetsprereqs( taken ) and currentterm in courseinstance.term and courseinstance.delay < term: print course takencopy[course] = '100' courselist[i] = "" i += 1 print "" courselist = filter(lambda x: x != "", courselist) taken.update(takencopy) #print courselist, taken #print taken if len(courselist): self.drawtimetable(courselist, taken, term=term + 1, skip=skip)
def _parse_event_tag(self, tag): """ """ div_tag = tag.find("div") if div_tag is None: return a_tag = div_tag.find("a") course_id = self._parse_course_id(a_tag.text) course_url = a_tag["href"] parts = self._split_html(div_tag, "br") stripped_parts = [] for part in parts: stripped_parts.append(part.strip()) course_title = stripped_parts[1] lecturer = stripped_parts[2] event_type = EVENT_TYPES_MAPPING.get(stripped_parts[3]) start_hour, end_hour = self._parse_event_hours(stripped_parts[4]) room = stripped_parts[5] course = Course(course_id, course_title, url=course_url) return TimetableEvent(event_type, course, lecturer, start_hour, end_hour, room)
def update_gui() -> None: """Update the GUI of the main application with the assignments from the database. """ c.execute('SELECT DISTINCT course FROM assignments') courses_list = c.fetchall() for course in courses_list: app.button.grid_forget() widget = CourseWidget(app.frame, Course(course[0])) app.button.grid(column=0, pady=10, padx=10) c.execute('''SELECT * FROM assignments WHERE course=? ORDER BY row''', (course[0],)) for row in c.fetchall(): if row[1] == 1: if row[2] is not None: widget.assignments[1][0].insert(0, row[2]) for i in range(1, 4): if row[i + 2] is not None: widget.assignments[1][i].insert(0, str(row[i + 2])) else: widget.add_assignment_gui() if row[2] is not None: widget.assignments[row[1]][0].insert(0, row[2]) for i in range(1, 4): if row[i + 2] is not None: widget.assignments[row[1]][i].insert(0, str(row[i + 2])) widget.update_assignments_gui()
def get_offering(self, id): #what happens if given id doesn't match the query data = self.__db_query( 'SELECT ID, COURSE, SESSION FROM COURSE_OFFERING WHERE ID = ? AND SURVEY_ID IS NULL', (id, )) print(data) for dat in data: print(dat) return Course(data[0][0], data[0][1], data[0][2])
def create_new_course(self, name, description, course_code, department, prereqs): try: new_course = Course(name=name, course_code=course_code, description=description, department=department) for prereq in prereqs: new_course.prereqs.append(prereq) db_session.add(new_course) db_session.flush() self.course_id = new_course.id except IntegrityError: db_session.rollback() log.error( "Error due to attempted insertion of duplicate new course") finally: db_session.commit() return self
def get_offerings(self): offerings = self.__db_query( 'SELECT ID, COURSE, SESSION FROM COURSE_OFFERING WHERE SURVEY_ID IS NULL ORDER BY SESSION, COURSE ASC', ()) data = [] seen = '' #courses = [] for offering in offerings: #courses = '' if offering[2] != seen: print('seen') seen = offering[2] courses = Courses(offering[2]) data.append(courses) #data.append(offering[1]) #courses = [] #data.append(courses) courses.add_course(Course(offering[0], offering[1], offering[2])) #courses.append(offering) return data
def confirm_course(self, code: str) -> None: """Create a new instance of CourseWidget, record this new course in the database, and destroy the Toplevel widget <self.new_course_window> iff the given course <code> does not already exist. Otherwise, an error window is created. """ matches = False # Loop through all existing courses recorded within the database and # stops once a match is found for code_tuple in c.execute('SELECT DISTINCT course FROM assignments'): if code in code_tuple: matches = True break # If a match was found (the course code already exists), an error window # is displayed if matches: error = Toplevel(self.new_course_window) error.title("Error!") error.geometry("+425+275") error.grid_rowconfigure(0, weight=1) error.grid_columnconfigure(0, weight=1) message = "Course with this code already exists!" Label(error, text=message).grid(row=0, column=0, padx=10, pady=10) error.grab_set() else: # Instantiate a new Course object and create its associated widgets # by creating an instance of CourseWidget course_obj = Course(code) CourseWidget(self.master, course_obj) self.new_course_window.destroy() # The new course is recorded in the database c.execute('INSERT INTO assignments (course, row) VALUES (?, ?)', (code, 1))
def iter_courses(self): """ """ courses = {} for event in self.iter_events(): event_course = event.course course_id = event_course.course_id lecturer = event.lecturer if course_id not in courses: courses[course_id] = Course(course_id, title=event_course.title, url=event_course.url, staff=CourseStaff()) course = courses[course_id] staff = course.staff if event.type == EventTypes.CLASS: staff.lecturers.add(lecturer) elif event.type == EventTypes.EXERCISE: staff.assistants.add(lecturer) return courses.itervalues()
def __init__(self, master: Frame, course_obj: Course) -> None: """Instantiate widgets associated with the given <course_obj> and place them onto <master>.""" # All widgets for this course are slaves of a frame from the main app self.master = master # Records the associated Course object and its average grade as # instance variables self.course = course_obj self.average = average = DoubleVar() average.set(course_obj.calculate_average()) # Create and place widgets associated with this course next_row = master.grid_size()[1] self.code = Label(master, text=self.course.code) self.code.grid(row=next_row, column=0) self.edit = Button(master, text="Edit assignments", command=self.edit_assignments) self.edit.grid(row=next_row, column=1) self.delete = Button(master, text="Delete course", command=self.delete_course) self.delete.grid(row=next_row, column=2) self.avg = Label(master, textvariable=average, font=("arial", 10, "bold")) self.avg.grid(row=next_row, column=3, padx=50) # Create the assignment editor window associated with this course # This is done using a separate method for the sake of clarity self.editor = None self.button = None self.assignments = None self.create_editor()
while True: do = raw_input(location + ":\n>> ") do = do.split() #print do while len(do) > 0: #print do if do[0] == "": do = do[1:] elif do[0].lower() == "help" or do[0].lower() == "h": print helpmenu do = do[1:] elif do[0].lower() == "goto" or do[0].lower() == "g": if len(do) == 1: do = do[1:] print "" break course = Course(do[1].upper()) location = course.name print "" #(location + ":") do = do[2:] elif do[0].lower() == "prereqs" or do[0].lower() == "prr": course.loadprereqs() try: course.print_prereqs() print "" except AttributeError: print "You have not selected a course.\n" except KeyError: print colored("Error parsing, we're sorry.\n", 'red') do = do[1:] elif do[0].lower() == "terms" or do[0].lower() == "trm": course.loadterm()
def get_courses(self): if self.courses == None: self.courses = Course.get_courses(self.data['id']) return self.courses
def add_courses(self, courses): self.courses = Course.add_courses(self.data['id'], courses)
A string conversion function that returns a string of form "code name minCredits ECTS" or "code name minCredits-maxCredits ECTS", depending on whether minCredits == maxCredits or not. An equality comparison function __eq__(self, other) that compares Course-objects bases on their names (this is similar to what was done in a lecture example regarding __lt__). A function __hash__(self) that returns the value self.name.__hash__(). Without going into details, having both the __eq__ and the __hash__-function enables us to use Course-objects as dictionary keys or set values. In this question we will not really create an own implementation but just reuse the __hash__-function of the attribute name. The end result is that in terms of dictionary keys or set values, two Course-objects are deeed to be identical if their names are identical. A function readCourses(filename) that reads course information from the file specified by the parameter filename and creates and returns a list of Course-objects that describe all courses in the file (in the order they appeared). Inspect the file courses.txt to see how the course information is structured. You need to do some suitable string matching operations in order to pick out the essential course information. You do not need to worry about duplicates (whether or not the same course appears more than once). """ import sys from courses import Course, readCourses # Read the course list courseList = readCourses(sys.argv[1]) # Try to add one more course courseList.append(Course("TIETA19", "Practical Programming in Python", 5, 5)) # Print out all types present in the courseList (should be only Course) print(set(map(type, courseList)), end="\n\n") # Print out all occurrences of course descriptions in the input (+ 1 added) print("All course occurrences:") for course in courseList: print(course) # Print out only unique occurrences (based on course name) print("\nUnique course occurrences:") for course in sorted(set(courseList), key=str): print(course)