当前位置: 首页>>代码示例>>Python>>正文


Python Course.materials方法代码示例

本文整理汇总了Python中courses.models.Course.materials方法的典型用法代码示例。如果您正苦于以下问题:Python Course.materials方法的具体用法?Python Course.materials怎么用?Python Course.materials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在courses.models.Course的用法示例。


在下文中一共展示了Course.materials方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mit

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import materials [as 别名]
def mit(debug=False):
    base_url = "http://ocw.mit.edu"
    r = requests.get(base_url + "/courses/")
    soup = BeautifulSoup(r.text)

    for course_list in soup("div",{"class":"course_list"}):
        category_name = str(course_list("div",{"class":"table_head"})[0]("a")[0].string).lower()
        for row in course_list("tr",{"class":"row"}) + course_list("tr",{"class":"alt-row"}):
            course_id = row("td")[2].string
            school_name = "mit"
            try:
                school = School.objects.filter(name__icontains=school_name)[0]
            except:
                school = School.objects.create(name=school_name)

            try:
                category = Category.objects.get(name=category_name)
            except:
                category = Category.objects.create(name=category_name)

            try:
                m = Course.objects.filter(type="mit").filter(course_id=str(course_id))[0]
            except:
                m = Course()
                
            material_names = [a['alt'] for a in row("td")[1]("a")]
            materials = []
            for name in material_names:
                try:
                    material = Material.objects.get(name=name)
                except:
                    material = Material.objects.create(name=name)
                materials.append(material)

            m.title = row("td")[3]("a")[0]("u")[0].string
            m.link = base_url + row("td")[3]("a")[0]['href']
            m.type = "mit"
            m.course_id = course_id
            m.school = school

            m.save()
            m.categories = [category]
            m.materials = materials
            m.save()

            if debug:
                print m
开发者ID:hbradlow,项目名称:MetaCourses,代码行数:49,代码来源:scraper.py

示例2: coursera

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import materials [as 别名]
def coursera(debug=False):
    r = requests.get("https://www.coursera.org/maestro/api/topic/list?full=1")
    data = json.loads(r.text)

    for course in data:
        course_id = course['id']
        school_name = course['universities'][0]['name'].lower()
        category_names = [a['name'].lower() for a in course['categories']]
        categories = []
        try:
            school = School.objects.filter(name__icontains=school_name)[0]
        except:
            school = School.objects.create(name=school_name)
        for category_name in category_names:
            try:
                category = Category.objects.get(name=category_name)
            except:
                category = Category.objects.create(name=category_name)
            categories.append(category)
        try:
            m = Course.objects.filter(type="coursera").filter(course_id=course_id)[0]
        except:
            m = Course()

        material_names = ["Assignments and solutions","Projects and examples","Multimedia content","Exams and solutions"]
        materials = []
        for name in material_names:
            try:
                material = Material.objects.get(name=name)
            except:
                material = Material.objects.create(name=name)
            materials.append(material)

        m.title = course['name']
        m.link = course['social_link']
        m.image_url = course['small_icon']
        m.course_id = course_id
        m.type = "coursera"
        m.school = school
        m.save()
        m.categories = categories
        m.materials = materials 
        m.save()

        if debug:
            print m
开发者ID:hbradlow,项目名称:MetaCourses,代码行数:48,代码来源:scraper.py

示例3: edx

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import materials [as 别名]
def edx(debug=False):
    base_url = "https://www.edx.org"
    r = requests.get(base_url + "/courses")
    soup = BeautifulSoup(r.text)

    for column in soup("section", {"class":"university-column"}):
        for course in column("article",{"class":"course"}):
            course_id = "/".join(course['id'].split("/")[:-1])
            school_name = course['id'].split("/")[0][:-1].lower()
            try:
                school = School.objects.filter(name__icontains=school_name)[0]
            except:
                school = School.objects.create(name=school_name)
            try:
                m = Course.objects.filter(type="edx").filter(course_id=course_id)[0]
            except:
                m = Course()

            material_names = ["Assignments and solutions","Projects and examples","Multimedia content","Exams and solutions"]
            materials = []
            for name in material_names:
                try:
                    material = Material.objects.get(name=name)
                except:
                    material = Material.objects.create(name=name)
                materials.append(material)

            m.title = " ".join(course("header")[0]("h2")[0].get_text().split(" ")[1:])
            m.link = base_url + course("a")[0]['href']
            m.image_url = base_url + course("img")[0]['src']
            m.type = "edx"
            m.course_id = course_id
            m.school = school
            m.save()

            m.materials = materials
            m.save()

            if debug:
                print m
开发者ID:hbradlow,项目名称:MetaCourses,代码行数:42,代码来源:scraper.py


注:本文中的courses.models.Course.materials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。