def find(): department_code = request.args.get('department_code') course_code = request.args.get('course_code') course = CourseRepository.find_by_department_and_course_code(department_code, course_code) if course is not None: return redirect(url_for('course.index', id=course.id)) flash('No course found ' + department_code + course_code, 'danger') return redirect(url_for('home_page'))
def threads(id): course = CourseRepository.find_by_id(id) if not course: abort(404) threads = MessageRepository.find_threads_of_course(course.id) form = NewThreadForCourseForm() if form.validate_on_submit(): message = Message() message.course_id = course.id message.user_id = current_user.id message.title = form.title.data message.message = form.message.data message = MessageRepository.create(message) return redirect(url_for('course.threads', id=id)) return render_template("course/threads.html", course=course, threads=threads, form=form, current_user=current_user)
def files(id): course = CourseRepository.find_by_id(id) if not course: abort(404) files = FileRepository.find_files_of_course(course.id) form = NewFileForCourseForm() if form.validate_on_submit(): f = form.file.data filename = secure_filename(str(uuid.uuid4()) + os.path.splitext(f.filename)[1]) f.save(os.path.join(app.config['UPLOAD_DIR'], 'files', filename)) file = File() file.course_id = course.id file.user_id = current_user.id file.title = form.title.data file.filename = filename file.original_filename = f.filename file.content_type = f.content_type file = FileRepository.create(file) return redirect(url_for('course.files', id=id)) return render_template("course/files.html", course=course, files=files, form=form, current_user=current_user)
def messages(course_id, id): course = CourseRepository.find_by_id(course_id) if not course: abort(404) thread = MessageRepository.find_by_id(id) if not thread: abort(404) if thread.course_id != course.id: abort(404) messages = MessageRepository.find_messages_of_thread(id) form = NewMessageForm() if form.validate_on_submit(): message = Message() message.course_id = course.id message.user_id = current_user.id message.title = thread.title message.thread_id = thread.id message.message = form.message.data message = MessageRepository.create(message) return redirect(url_for('course.messages', course_id=course_id, id=id)) return render_template("course/messages.html", course=course, messages=messages, form=form, current_user=current_user, thread=thread)
def search(): query = request.args.get('query') courses = CourseRepository.search(query) return render_template("course/search.html", query=query, courses=courses)
def index(id): course = CourseRepository.find_by_id(id) if not course: abort(404) sections = SectionRepository.find_sections_of_course(id) return render_template("course/index.html", course=course, sections=sections)
def get_course(self): if self.course is None: self.course = CourseRepository.find_by_id(self.course_id) return self.course
def home_page(): courses = CourseRepository.find_random(10) sections = SectionRepository.find_random(10) teachers = TeacherRepository.find_random(10) department_codes = CourseRepository.find_department_codes() return render_template('home.html', sections=sections, courses=courses, teachers=teachers, department_codes=department_codes)
def parse_itu(): page = requests.get('http://www.sis.itu.edu.tr/tr/ders_programlari/LSprogramlar/prg.php') tree = html.fromstring(page.content) #This will create a list of course_codes course_codes = tree.xpath('//select[@name="bolum"]/option[not(@selected)]/text()') # print 'Course Codes: ' for course_code in course_codes: link = 'http://www.sis.itu.edu.tr/tr/ders_programlari/LSprogramlar/prg.php?fb=' + course_code page = requests.get(link.strip()) tree = html.fromstring(page.content) tds = tree.xpath('//table[@class="dersprg"]/tr[@onmouseover]/td') courses = [] while len(tds) > 14: pice = tds[:14] courses.append(pice) tds = tds[14:] courses.append(tds) if len(courses[0]) == 0: continue sections = [] for course in courses: course_sections = [{}] course_sections[0]['crn'] = course[0].text course_sections[0]['course_code'] = course[1].getchildren()[0].text course_sections[0]['title'] = course[2].text course_sections[0]['instructor'] = course[3].text course_sections[0]['capacity'] = course[8].text course_sections[0]['enrolled'] = course[9].text buildings = course[4].text_content() days = list(filter(None, course[5].text_content().split(' '))) hours = list(filter(None, course[6].text_content().split(' '))) if len(course[7].text_content().strip()) == 0: classes_content = "---" else: classes_content = course[7].text_content() classes = list(filter(None, classes_content.split(' '))) sections_count = len(buildings) // 3 for x in range(0,sections_count): if x >= len(course_sections): course_sections.append(course_sections[x-1].copy()) course_section = course_sections[x] course_section['building'] = buildings[(x * 3): ((x + 1) * 3)] course_section['day'] = days[x] course_section['hour'] = hours[x] course_section['class'] = classes[x] for data in course_sections: course_codes = data['course_code'].split(' ') course = CourseRepository.find_by_department_and_course_code(course_codes[0], course_codes[1]) if not course: course = CourseRepository.create(Course(course_codes[0], course_codes[1], data['title'])) instructor = data['instructor'].split(',')[0] teacher = TeacherRepository.find_by_name(instructor) if not teacher: teacher = TeacherRepository.create(Teacher(instructor)) section = Section() section.crn = int(data['crn']) section.building = data['building'] section.day = data['day'] section.time = data['hour'] section.room = data['class'] section.capacity = data['capacity'] section.enrolled = data['enrolled'] section.course_id = course.id section.teacher_id = teacher.id SectionRepository.create(section) return redirect(url_for('home_page'))