def pop_course(self): #Reads one course from file #returns None if course isn't scheduled for this year #Otherwise gives course line=self.read_line() #Occasionally instead of a course's information a line will have a new #department, if this is the case set the department to the current line #and then read in another line which should be a course code if self.is_dept(line): self.current_dept=line line=self.read_line() course_code=line if not self.is_course_code(course_code): print(course_code) print(self.line_no) assert self.is_course_code(course_code) course_name=self.read_line() line=self.read_line() if line in "NOT OFFERED":#This exact string is used to indicate not offered courses return None course_term=int(line[-1])#Get the last character of the line, "T1" -> 1 course_section=self.read_line()#DAY or NIGHT are the exact strings assert self.is_section(course_section) #All of the course's information has been loaded so the course is created new_course=Course(self.current_dept,course_code,course_name,course_term,course_section) #If information about what site the course is for is given, it is skipped over if "SITE STUDENTS" in self.peek_line(): self.read_line() #If the course is cancelled read ahead until the next line is a course or a department if "CANCELLED" in self.peek_line(): while not (self.is_course_code(self.peek_line()) or self.is_dept(self.peek_line())): self.read_line() return None #Read in all of the courses segments while (self.is_class_type(self.peek_line()) or "EOW" in self.peek_line() or "CANCELLED" in self.peek_line() or "SITE" in self.peek_line()): new_course_segment=self.read_course_segment() if new_course_segment: new_course.add(new_course_segment) if "EOW" in self.peek_line() or "SITE" in self.peek_line(): self.read_line() new_course.consolidate_courses() return new_course
def pop_course(self): #Reads one course from file #returns None if course isn't scheduled for this year #Otherwise gives course line = self.read_line() #Occasionally instead of a course's information a line will have a new #department, if this is the case set the department to the current line #and then read in another line which should be a course code if self.is_dept(line): self.current_dept = line line = self.read_line() course_code = line #There are really wierd edge cases were this line isn't a course code #This reads until a course code, solving those errors while not self.is_course_code(course_code): course_code = self.read_line() assert self.is_course_code(course_code) course_name = self.read_line() line = self.read_line() if line in "NOT OFFERED": #This exact string is used to indicate not offered courses return None course_term = int( line[-1]) #Get the last character of the line, "T1" -> 1 course_section = self.read_line() #DAY or NIGHT are the exact strings assert self.is_section(course_section) #All of the course's information has been loaded so the course is created new_course = Course(self.current_dept, course_code, course_name, course_term, course_section) #If information about what site the course is for is given, it is skipped over if "SITE STUDENTS" in self.peek_line(): self.read_line() #If the course is cancelled read ahead until the next line is a course or a department if "CANCELLED" in self.peek_line(): self.read_until([self.is_course_code, self.is_dept]) return None #Read in all of the courses segments while (self.is_class_type(self.peek_line()) or self.is_ignorable(self.peek_line())): new_course_segment = self.read_course_segment() if new_course_segment: new_course.add(new_course_segment) if self.is_ignorable(self.peek_line()): self.read_line() #new_course.consolidate_segments() return new_course