本文整理匯總了Python中models.Course.questions方法的典型用法代碼示例。如果您正苦於以下問題:Python Course.questions方法的具體用法?Python Course.questions怎麽用?Python Course.questions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Course
的用法示例。
在下文中一共展示了Course.questions方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: scrape_course
# 需要導入模塊: from models import Course [as 別名]
# 或者: from models.Course import questions [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)