Exemplo n.º 1
0
 def post(self):
     keyword = self.get_argument('keyword', None)
     criteria = self.get_argument('criteria', None)
     if keyword:
         results = []
         if not criteria:
             results = Course.get_courses_by_keyword(keyword)
         elif criteria == 'teacher':
             results = Course.get_courses_by_teacher_keyword(keyword)
         else:
             results = Course.get_courses_by_title_keyword(keyword)
         print keyword
         res = {"all": []}
         for i in results:
             res["all"].append({
                 "name": i.name,
                 "teacher": i.teacher,
                 "category": i.category,
                 "first": i.first_charac,
                 "rating": i.get_rating(),
                 "color": i.get_color()
                 })
         if len(res["all"]) == 0:
             self.write("2")
         else:
             json_str = json.dumps(res, ensure_ascii=False)
             self.write(json_str)
     else:
         self.write("0");
Exemplo n.º 2
0
 def post(self):
     title = self.get_argument('title', None)
     teacher = self.get_argument('teacher', None)
     category = self.get_argument('category', None)
     comment = self.get_argument('comment', None)
     author = self.get_argument('author', None)
     step = self.get_argument('step', None)
     rating = self.get_argument('rating', None)
     force = self.get_argument('force', None)
     step = int(step)
     if title and teacher and category and comment and author and rating:
         resu = Course.get_course_by_cate_teac_name(int(category), teacher, title)
         if not force and resu:
             self.write('2')
             return
         elif resu and int(force) == 1:
             cmtid = Course.add_comment(resu.cid, comment, author)
             Course.add_rating(resu.cid, int(rating))
             self.write("1")
             return
         res = Course.get_course_by_name(title)
         if res and step == 1:
             result = {"all": []}
             for i in res:
                 result["all"].append({"name": i.name, "teacher": i.teacher, "category": i.get_category_name(), "comments": len(i.get_comments()), "rating": i.get_rating()})
             json_str = json.dumps(result, ensure_ascii=False)
             self.write(json_str)
         else:
             cid = Course.insert_course({"name": title, "teacher": teacher, "category": int(category) })
             Course.add_comment(cid, comment, author)
             Course.add_rating(int(cid), int(rating))
             self.write("1")
     else:
         self.write("0")
Exemplo n.º 3
0
 def post(self):
     comment = self.get_argument("content", None)
     author = self.get_argument("author", None)
     rating = self.get_argument("rating", None)
     cid = self.get_argument("cid", None)
     if comment and author and rating and cid:
         cmtid = Course.add_comment(int(cid), comment, author)
         Course.add_rating(int(cid), int(rating))
         self.write(str(cmtid))
     else:
         self.write("-1")
Exemplo n.º 4
0
 def get(self):
     cid = self.get_argument('cid', None)
     cmtid = self.get_argument('cmtid', None)
     if cid:
         course = Course.get_course_by_cid(cid)
         self.render('updateCourse.html', course=course)
     if cmtid:
         comment = Comment.get_comment_by_cmtid(cmtid)
         self.render('updateComment.html', comment=comment)
Exemplo n.º 5
0
 def get(self):
     cid = self.get_argument('cid', None)
     if cid:
         res = Course.get_course_by_cid(int(cid))
         res_list = res.get_all_comments()
         adict = {"all": []}
         for item in res_list:
             adict["all"].append({"cmtid": item.cmtid, "comment": item.comment, "like": item.like, "unlike": item.unlike, "author": item.author, "status": item.status})
         json_str = json.dumps(adict, ensure_ascii=False)
         self.write(json_str)
     else:
         self.writer(0)
Exemplo n.º 6
0
 def post(self):
     cid = self.get_argument('cid', None)
     if cid:
         comments = Course.get_all_comments(cid)
         a = []
         for i in comments:
             a.append({'cmtid': i.cmtid, 'author': i.author, 'content': i.comment, 'like': i.like, 'unlike': i.unlike, 'status': i.status })
         b = {'all': a}
         json_str = json.dumps(b, ensure_asii = False)
         self.write(json_str)
     else:
         self.write('0')
def load_courses():
    courses_list = []
    with open('courses_list.txt', 'r', encoding='iso-8859-1') as scraped_data:
        line = scraped_data.readline()
        cnt = 1
        while line:
            # print("Line {}: {}".format(cnt, line.strip()))
            course = Course()
            sigle = re.search('\d\w\w\w\d\d\d', line)
            line_without_sigle = line[8:]

            splited_line = line_without_sigle.split('(')
            # print(result)
            if sigle:
                course.sigle = (sigle.group())
                course.name = splited_line[0]

                print(course.sigle)
                print(course.name)
                course.save()

            else:
                if line.strip() == "du":
                    for index in range(12):
                        if index == 1 or index == 2 or index == 4 or index == 5 or index == 7 or index == 9 or index == 11:
                            # print(line)
                            a = 1
                        line = scraped_data.readline()
            courses_list.append(course)
            line = scraped_data.readline()
Exemplo n.º 8
0
    def post(self):
        cid = self.get_argument('cid', None)
        cmtid = self.get_argument('cmtid', None)
        if cid:
            name = self.get_argument('name', None)
            category = self.get_argument('category', None)
            status = self.get_argument('status', None)
            sums = self.get_argument('sums', None)
            count = self.get_argument('count', None)
            teacher = self.get_argument('teacher', None)
            Course.update_course({
                "cid": int(cid),
                "name": name,
                "category": int(category),
                "status": int(status),
                "sums": int(sums),
                "count": int(count),
                "teacher": teacher
                })
            self.redirect('/admin')

        if cmtid:
            author = self.get_argument('author', None)
            like = self.get_argument('like', None)
            unlike = self.get_argument('unlike', None)
            status = self.get_argument('status', None)
            comment = self.get_argument('comment', None)
            Comment.update_comment(int(cmtid), {
                "cmtid": int(cmtid),
                "author": author,
                "like": int(like),
                "unlike": int(unlike),
                "comment": comment,
                "status": int(status),
                })
            self.redirect('/admin')
Exemplo n.º 9
0
    def get(self, keyword):
        if keyword:
            results = Course.get_courses_by_keyword(keyword)
            cates = sum_of_categories(results)
            cc = ["公选", "专选", "公必", "专必", "体育"]
            categories = []
            for i in xrange(5):
                if cates[i] != 0:
                    categories.append({"catecode": i+1, "name": cc[i], "count": cates[i]})
            if self.is_mobile():
                self.render('mobileResult.html',
                    page='result',
                    results=results,
                    keyword=keyword,
		    kwd=None
                    )
            else:
                self.render('result.html',
                    clickable="True",
                    keyword=keyword,
                    categories=categories,
                    results=results
                    )
Exemplo n.º 10
0
 def get(self, category, teacher, name):
     kwd = self.get_argument('keyword', None)
     if category == "体育":
         category = 5
     if category == "公选":
         category = 1
     if category  == "专选":
         category = 2
     if category  == "公必":
         category = 3
     if category  == "专必":
         category = 4
     res = Course.get_course_by_cate_teac_name(category, teacher, name)
     if res:
         if self.is_mobile():
             self.render('mobileDetail.html', page='detail', course=res, kwd=kwd)
         else:
             self.render('detail.html', course=res, clickable="True")
     else:
         if self.is_mobile():
             self.render('404.html')
         else:
             self.render('404.html')
Exemplo n.º 11
0
def _get_course_properties():
    return Course.get_environ(sites.get_course_for_current_request())
Exemplo n.º 12
0
 def get(self):
     courses = Course.get_all_courses()
     self.render('data-base.html', courses=courses)
Exemplo n.º 13
0
 def get(self):
     if self.is_mobile():
         self.render('mobileIndex.html', page='index', res=Course.get_random_courses())
     else:
         self.render('index.html')
Exemplo n.º 14
0
    def getData(self, courses: dict) -> list:
        """
        Scrapes the KFUPM Course offering page and returns a
        courses list containing course objects
        """

        # Initializing necessary attributes
        self.setTerms()
        self.setDepartments()
        self.setFormAttributes()

        for term in self.terms:
            for dept in self.depts:
                logging.info(f"\t{term}: {dept}")

                try:
                    response = self.session.post(self.url,
                                                 data=self.getPayload(
                                                     term, dept))
                except requests.RequestException as e:
                    logging.error(e)

                soup = BeautifulSoup(response.text, 'html.parser')
                numberOfCourses = 0

                for row in soup.find_all("div", class_="trow"):
                    # fetch data of ONE course
                    data = self.getCourseData(row)

                    # splitting course name and sections
                    # as required by the schema
                    data["Section"], data["Course"] = (
                        data["Course-Sec"].split("-")[1],
                        data["Course-Sec"].split("-")[0])
                    # splitting Time as start_time and
                    # end_time as required by schema
                    data["start_time"], data["end_time"] = (
                        data["Time"].split("-")[0], data["Time"].split("-")[1])

                    # setting time as -1 to indicate
                    # that the start_time / end_time
                    # fields are empty
                    if len(data["start_time"]) == 0:
                        data["start_time"] = -1

                    if len(data["end_time"]) == 0:
                        data["end_time"] = -1

                    # removing redundant keys
                    data.pop("Course-Sec", None)
                    data.pop("Time", None)
                    numberOfCourses += 1

                    # storing name and term of latest course scraped
                    # to check whether the previous course that was
                    # scraped is the same so as to only append a
                    # new section to the course object
                    courseID = data["Course"] + term

                    section = Section(data["CRN"], data["Section"],
                                      data["Instructor"], data["Activity"],
                                      data["Day"], data["Loc"],
                                      data["start_time"], data["end_time"],
                                      data["Status"])

                    # If the new course does not already exist, create a new
                    # course object and append it to the courses dict,
                    # otherwise only create a new section object and
                    # append it to courses.sections
                    if (courseID not in courses):
                        sections = []
                        sections.append(section)

                        course = Course(data["Course"], data["Course Name"],
                                        term, dept, sections)

                    else:
                        # Only appends the new section of the same course
                        courses[courseID].sections.append(section)

                    # Set course to unique courseID
                    courses[courseID] = course
                    logging.info(f"\t {courseID} created")

        return courses
Exemplo n.º 15
0
 def get_environ(self):
     return Course.get_environ(self)
Exemplo n.º 16
0
 def get(self):
     Course.delete_course_by_status()
     self.redirect('/admin')
Exemplo n.º 17
0
 def get_course(self):
     """Get current course."""
     if not self.course:
         self.course = Course(self)
     return self.course
Exemplo n.º 18
0
def _get_course_properties():
    return Course.get_environ(sites.get_course_for_current_request())
Exemplo n.º 19
0
def add_course(course: Course):
    fakedb.append((course.dict()))
    return fakedb[-1]
Exemplo n.º 20
0
 def get(self):
     cid = self.get_argument('cid', None)
     if cid:
         Course.change_status(int(cid), 1)
         self.redirect('/admin')
Exemplo n.º 21
0
 def get_course(self):
     if not self.course:
         self.course = Course(self)
     return self.course
Exemplo n.º 22
0
 def get_course(self):
     """Get current course."""
     if not self.course:
         self.course = Course.get(self.app_context)
     return self.course
Exemplo n.º 23
0
courses = [
    Course(
        **{
            "id":
            "8SoStds",
            "name":
            "8th Grade Social Studies",
            "section":
            "A",
            "grade":
            8,
            "subject":
            "SOCIAL_STUDIES",
            "descriptionHeading":
            "8th Grade Social Studies A",
            "description":
            "Geography - Solar System, Our Planet - Earth",
            "ownerId":
            "116353579384483626788",
            "creationTime":
            "2018-05-26T20:10:12.481Z",
            "updateTime":
            "2018-05-26T20:14:03.185Z",
            "courseState":
            "ACTIVE",
            "imageUri":
            "https://gnext18-v5.appspot.com/play/img/social_studies.jpg",
            "calendarId":
            "*****@*****.**"
        }),
    Course(