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


Python Course.validate方法代码示例

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


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

示例1: scrape_course

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import validate [as 别名]
def scrape_course(requester, output_dir, course_id, year, term):
    """
    Scrapes all data for a particluar course, including ratings, comments,
    and instructor ratings.
    """
    # This course is weird. Let's skip it.
    if course_id in (44050,):
        print('There is some weird shit going on with course {}'.format(course_id))
        return

    c = Course(course_id=course_id, year=year, term=term)
    base_url = '/course_evaluation_reports/fas/course_summary.html'
    url = '{base_url}?course_id={course_id}'.format(base_url=base_url,
                                                    course_id=course_id)

    soup = requester.make_request(url)

    # Get course name, department, enrollment, etc.
    if soup.h1 is None:
        print('No data for course {}'.format(course_id))
        return

    title = soup.h1.text
    colon_loc = title.find(':')
    c.department, c.course_code = title[:colon_loc].split()
    c.course_name = title[colon_loc + 2:]

    stats = soup.select('#summaryStats')[0].text.split()
    c.enrollment = int(stats[1])
    c.evaluations = int(stats[3])

    # Get course ratings
    graph_reports = soup.select('.graphReport')
    if not graph_reports:
        print('No data for course {}'.format(course_id))
        return

    c.ratings = []
    for graph_report in graph_reports[:-1]:
        c.ratings += scrape_ratings(graph_report)

    # Get reasons for why people signed up
    c.reasons = scrape_reasons(graph_reports[-1])

    c.instructors = scrape_instuctors(requester, course_id)
    c.questions = scrape_questions(requester, course_id)

    c.validate()
    filename = os.path.join(output_dir, '{}.json'.format(c.course_id))
    with open(filename, 'w') as f:
        json.dump(c.to_json_dict(), f, indent=3)
开发者ID:jpalay,项目名称:qscrapy,代码行数:53,代码来源:scrapers.py


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