def listSectionStatus(): try: requested = request.form r= Registrar("UPENN_OD_emmK_1000220", "2g0rbtdurlau4didkj9schee95") course = r.search({'course_id': requested['course_id']}) d = {} for x in course: l = [] s = x["section_id"] print ("section" + s) if x["is_closed"]: l.append("Closed") print "is_closed" else: l.append("Open") print "is _open" if (x["activity_description"] == "Lecture"): p = x["instructors"][0]["name"] elif (x["activity_description"] == "Recitation"): p = x["primary_instructor"] else: p = "" print "professor: " + p l.append(p) t = x["first_meeting_days"] print "time: " + t l.append(t) d[s] = l return render_template("courses.html", d = d) except ValueError as e: return render_template("courses.html", d={})
def get_opening(course): try: print "get_opening" r = Registrar("UPENN_OD_emmK_1000220", "2g0rbtdurlau4didkj9schee95") courses = r.search({'course_id': course['id']}) # runs once for c in courses: course['is_closed'] = (c['is_closed'] == True) return course except OSError: print "error in get_opening" except ValueError as e: print e
def load_all_courses(): r = Registrar("UPENN_OD_emoG_1000340", "7vgj93rojjmbuh3rrsgs7vc2ic") courses = r.search({'course_id': ""}) # runs once for c in courses: id = c['section_id'] is_closed = (c['is_closed'] == True) try: if (c["activity_description"] == "Lecture"): instructor = c["instructors"][0]["name"] elif (c["activity_description"] == "Recitation"): instructor = c["primary_instructor"] else: instructor = "" except IndexError: instructor = "" print "adding: " + id db.hmset(id, {"id":id, "is_closed": is_closed, "instructor": instructor})
def load_all_courses(): r = Registrar("UPENN_OD_emoG_1000340", "7vgj93rojjmbuh3rrsgs7vc2ic") courses = r.search({'course_id': ""}) # runs once for c in courses: id = c['section_id'] is_closed = (c['is_closed'] == True) try: if (c["activity_description"] == "Lecture"): instructor = c["instructors"][0]["name"] elif (c["activity_description"] == "Recitation"): instructor = c["primary_instructor"] else: instructor = "" except IndexError: instructor = "" print "adding: " + id db.hmset(id, { "id": id, "is_closed": is_closed, "instructor": instructor })
class ScheduleBuilder(object): def __init__(self): self.registrar = Registrar('UPENN_OD_emFc_1001364', '6kl4eonkquheuti65e32qick6l') os.environ['PCR_AUTH_TOKEN']='kdutFhMEbUaKdvQbcRKszEiwZeThFs' def set_requirements(self, reqs): if reqs == None or len(reqs) == 0: return 'Must have at least one requirement' total_credits = 0 for req in reqs: total_credits = total_credits + reqs[req] if total_credits > 6.5: return 'Why the f**k are you taking more than six and a half classes, go outside' self.req_numbers = reqs return True def find_all_classes(self, req_type, course_level_above=None, course_level_below=None, starts_after=None): # First enter default params for all courses print "Finding classes with params: " search_params = {} search_params['term'] = '2015C' search_params['fulfills_requiremement'] = req_type #search_params['status'] = 'O' #search_params['is_cancelled'] = False # if course_level_above is not None: # search_params['course_level_above'] = course_level_above # if course_level_below is not None: # search_params['course_level_below'] = course_level_below # if starts_after is not None: # search_params['starts_at_or_after_hour'] = starts_after print search_params all_courses = self.registrar.search(search_params) print "request finished" return all_courses # def add_ratings(courses): # for course in courses: # course_info = penncoursereview(CourseParser.get_course_department(course), CourseParser.get_course_number(course), \ # CourseParser.get_section(course)) # difficulty_rating = course_info./ def enter_preferences(self, starts_after=None, ends_before=None, no_class_days=None, difficulty_limit=None, work_limit=None, lunch_break=None): self.all_valid_classes = [] for req in self.req_numbers: print req self.all_valid_classes = self.all_valid_classes + self.get_all_courses(self.find_all_classes(req, starts_after=starts_after)) self.filter_class_days(self.all_valid_classes, no_class_days) self.all_valid_classes.sort(cmp_course) def cmp_course(course1, course2): start_time1 = course1['meetings'][0]['start_time_24'] start_time2 = course2['meetings'][0]['start_time_24'] if start_time1 < start_time2: return -1 elif start_time2 < start_time1: return 1 else: return 0 def filter_class_days(self, req_classes, no_class_days): for req in req_classes: current_classes = req_classes[req] for i in range(0, len(req_classes[req]) - 1): if self.class_meets_on_days(current_classes[i]): del current_classes[i] def find_schedule(self): result = self.find_schedule_recurse(self.all_valid_classes, self.req_numbers, []) return result def find_schedule_recurse(self, all_courses, req_numbers, selected_classes): if self.total_reqs_remaining(req_numbers) == 0: return selected_classes elif len(all_courses) == 0: return False for i in range(0, len(all_courses)): course_to_add = all_courses[i] # if course is not needed in requirements all_course_reqs = CourseParser.get_requirements(course_to_add) if course_to_add not in all_course_reqs: del all_courses[i] continue selected_classes.append(course_to_add) all_courses = courseComparator.filter_out_courses_that_overlap(course_to_add, all_courses) for req in all_course_reqs: req_numbers[req] = req_numbers[req] - 1 return find_schedule_recurse(all_courses, req_numbers, selected_classes) def total_reqs_remaining(self, req_numbers): total = 0 for req in req_numbers: total = total + req_numbers[req] return total def get_all_courses(self, generator): print "changing generator into list" all_courses_list = [] num = 0 for item in generator: all_courses_list.append(item) # print json.dumps(item, indent=4, sort_keys=True, separators=(', ', ': ')) print num num = num + 1 print "created list with " + len(all_courses_list) + " items" return all_courses_list
class ScheduleBuilder(object): def __init__(self): self.registrar = Registrar('UPENN_OD_emFc_1001364', '6kl4eonkquheuti65e32qick6l') os.environ['PCR_AUTH_TOKEN'] = 'kdutFhMEbUaKdvQbcRKszEiwZeThFs' def set_requirements(self, reqs): if reqs == None or len(reqs) == 0: return 'Must have at least one requirement' total_credits = 0 for req in reqs: total_credits = total_credits + reqs[req] if total_credits > 6.5: return 'Why the f**k are you taking more than six and a half classes, go outside' self.req_numbers = reqs return True def find_all_courses(self, req_type, course_level_above=None, course_level_below=None, starts_after=None): # First enter default params for all courses print "Finding classes with params: " search_params = {} search_params['fulfills_requirement'] = req_type search_params['term'] = '2015C' search_params['status'] = 'O' search_params['is_cancelled'] = False # if course_level_above is not None: # search_params['course_level_above'] = course_level_above # if course_level_below is not None: # search_params['course_level_below'] = course_level_below # if starts_after is not None: # search_params['starts_at_or_after_hour'] = starts_after all_courses = self.registrar.search(search_params) print "request finished" return all_courses # def add_ratings(courses): # for course in courses: # course_info = penncoursereview(CourseParser.get_course_department(course), CourseParser.get_course_number(course), \ # CourseParser.get_section(course)) # difficulty_rating = course_info./ def enter_preferences(self, starts_after=None, ends_before=None, no_class_days=None, difficulty_limit=None, work_limit=None, lunch_break=None): self.all_valid_courses = [] for req in self.req_numbers: print req self.all_valid_courses = self.all_valid_courses + self.generator_to_list( self.find_all_courses(req, starts_after=starts_after)) print "No class days" if no_class_days is not None: print 'befroe' no_class_days = CourseParser.convert_to_ascii(no_class_days) print "middle" print self.all_valid_courses self.all_valid_courses = self.filter_course_days( self.all_valid_courses, no_class_days) print "after" self.all_valid_courses.sort(self.cmp_course) print 'double smeag' return True def cmp_course(self, course1, course2): if len(course1['meetings']) == 0 and len(course2['meetings']): return 0 elif len(course1['meetings']) == 0: return 1 elif len(course2['meetings']) == 0: return -1 start_time1 = course1['meetings'][0]['start_time_24'] start_time2 = course2['meetings'][0]['start_time_24'] if start_time1 < start_time2: return -1 elif start_time2 < start_time1: return 1 else: return 0 def filter_course_days(self, courses, no_class_days): correct_courses = list() for i, course in enumerate(courses): if courseComparator.course_meets_on_days(course, no_class_days): continue else: correct_courses.append(course) return correct_courses def find_schedule(self): result = self.find_schedule_recurse(self.all_valid_courses, self.req_numbers, []) return result def find_schedule_recurse(self, all_courses, req_numbers, selected_classes): if self.total_reqs_remaining(req_numbers) == 0: return selected_classes elif len(all_courses) == 0: return False for i in range(0, len(all_courses) - 1): print i course_to_add = all_courses[i] # if course is not needed in requirements all_course_reqs = CourseParser.get_requirements(course_to_add) fulfills_requirement = False for req in all_course_reqs: if req in req_numbers.keys() and req_numbers[req] > 0: fulfills_requirement = True break if not fulfills_requirement: print 'doesnt fulfill req' continue print 'ADDING COURSE' selected_classes.append(course_to_add) courses_after_selected = all_courses[i:] all_courses = courseComparator.filter_out_courses_that_overlap( course_to_add, courses_after_selected) for req in all_course_reqs: if req in req_numbers.keys() and req_numbers[req] > 0: req_numbers[req] = req_numbers[req] - 1 break return self.find_schedule_recurse(courses_after_selected, req_numbers, selected_classes) def total_reqs_remaining(self, req_numbers): total = 0 for req in req_numbers: total = total + req_numbers[req] return total def generator_to_list(self, generator): all_courses_list = [] num = 0 for item in generator: all_courses_list.append(item) num = num + 1 return all_courses_list
class ScheduleBuilder(object): def __init__(self): self.registrar = Registrar('UPENN_OD_emFc_1001364', '6kl4eonkquheuti65e32qick6l') os.environ['PCR_AUTH_TOKEN']='kdutFhMEbUaKdvQbcRKszEiwZeThFs' def set_requirements(self, reqs): if reqs == None or len(reqs) == 0: return 'Must have at least one requirement' total_credits = 0 for req in reqs: total_credits = total_credits + reqs[req] if total_credits > 6.5: return 'Why the f**k are you taking more than six and a half classes, go outside' self.req_numbers = reqs return True def find_all_courses(self, req_type, course_level_above=None, course_level_below=None, starts_after=None): # First enter default params for all courses print "Finding classes with params: " search_params = {} search_params['fulfills_requirement'] = req_type search_params['term'] = '2015C' search_params['status'] = 'O' search_params['is_cancelled'] = False # if course_level_above is not None: # search_params['course_level_above'] = course_level_above # if course_level_below is not None: # search_params['course_level_below'] = course_level_below # if starts_after is not None: # search_params['starts_at_or_after_hour'] = starts_after all_courses = self.registrar.search(search_params) print "request finished" return all_courses # def add_ratings(courses): # for course in courses: # course_info = penncoursereview(CourseParser.get_course_department(course), CourseParser.get_course_number(course), \ # CourseParser.get_section(course)) # difficulty_rating = course_info./ def enter_preferences(self, starts_after=None, ends_before=None, no_class_days=None, difficulty_limit=None, work_limit=None, lunch_break=None): self.all_valid_courses = [] for req in self.req_numbers: print req self.all_valid_courses = self.all_valid_courses + self.generator_to_list(self.find_all_courses(req, starts_after=starts_after)) print "No class days" if no_class_days is not None: print 'befroe' no_class_days = CourseParser.convert_to_ascii(no_class_days) print "middle" print self.all_valid_courses self.all_valid_courses = self.filter_course_days(self.all_valid_courses, no_class_days) print "after" self.all_valid_courses.sort(self.cmp_course) print 'double smeag' return True def cmp_course(self, course1, course2): if len(course1['meetings']) == 0 and len(course2['meetings']): return 0 elif len(course1['meetings']) == 0: return 1 elif len(course2['meetings']) == 0: return -1 start_time1 = course1['meetings'][0]['start_time_24'] start_time2 = course2['meetings'][0]['start_time_24'] if start_time1 < start_time2: return -1 elif start_time2 < start_time1: return 1 else: return 0 def filter_course_days(self, courses, no_class_days): correct_courses = list() for i, course in enumerate(courses): if courseComparator.course_meets_on_days(course, no_class_days): continue else: correct_courses.append(course) return correct_courses def find_schedule(self): result = self.find_schedule_recurse(self.all_valid_courses, self.req_numbers, []) return result def find_schedule_recurse(self, all_courses, req_numbers, selected_classes): if self.total_reqs_remaining(req_numbers) == 0: return selected_classes elif len(all_courses) == 0: return False for i in range(0, len(all_courses) - 1): print i course_to_add = all_courses[i] # if course is not needed in requirements all_course_reqs = CourseParser.get_requirements(course_to_add) fulfills_requirement = False for req in all_course_reqs: if req in req_numbers.keys() and req_numbers[req] > 0: fulfills_requirement = True break if not fulfills_requirement: print 'doesnt fulfill req' continue print 'ADDING COURSE' selected_classes.append(course_to_add) courses_after_selected = all_courses[i:] all_courses = courseComparator.filter_out_courses_that_overlap(course_to_add, courses_after_selected) for req in all_course_reqs: if req in req_numbers.keys() and req_numbers[req] > 0: req_numbers[req] = req_numbers[req] - 1 break return self.find_schedule_recurse(courses_after_selected, req_numbers, selected_classes) def total_reqs_remaining(self, req_numbers): total = 0 for req in req_numbers: total = total + req_numbers[req] return total def generator_to_list(self, generator): all_courses_list = [] num = 0 for item in generator: all_courses_list.append(item) num = num + 1 return all_courses_list