def fromDataJson(cls, json, courseName): sec = CourseSection() grabs = [ ('classNumber', 'class_number'), ('campus', 'campus_location'), ('building', 'building'), ('room', 'room'), ('enrlCap', 'enrollment_cap'), ('enrlTot', 'enrollment_total'), ('related1', 'related_component_1'), ('related2', 'related_component_2'), ('instructor', 'instructor'), ('instructorId', 'instructor_id') ] for (k, jk) in grabs: if jk in json: setattr(sec, k, json[jk]) startTimeInt = int(json['start_time']) endTimeInt = int(json['end_time']) startHours = startTimeInt / 100 endHours = endTimeInt / 100 startMinutes = startTimeInt % 100 endMinutes = endTimeInt % 100 sec.addOfferings(CourseOffering.offeringsFromDaysAndTime( json['days'], startHours * 60 * 60 + startMinutes * 60, endHours * 60 * 60 + endMinutes * 60)) sec.dateString = CourseOffering.displayString(sec.offerings) sec.courseName = courseName sec.sectionNum = " ".join(json["component_section"].split()[1:]) return sec
def addOfferings(self, newOfferings): self.offerings += newOfferings self.offerings = CourseOffering.uniqueOfferings(self.offerings) #Removes weird parse errors self.hasValidDate = len(self.offerings) > 0