本文整理汇总了Python中course.Course.get_events方法的典型用法代码示例。如果您正苦于以下问题:Python Course.get_events方法的具体用法?Python Course.get_events怎么用?Python Course.get_events使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course.Course
的用法示例。
在下文中一共展示了Course.get_events方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import get_events [as 别名]
def generate(self, student_id):
# This is the URL where the source of schedule come from.
course_table_url = self.__get_url() + "/StudentQuery/CtrlViewQueryCourseTable"
# Create the request to get the raw data of schedule.
request = Request(url=course_table_url, data=urlencode({'studentNo': student_id}).encode('utf-8'))
# Get and return the raw data.
data = self.__opener.open(request).read().decode('utf-8')
# First extract data from HTML.
initial_data = re.findall(pattern=r"<tr>(.+?)</tr>", string=data, flags=re.S)
# Create a list of a list of course info.
course_list = []
for extracted_data in initial_data:
items = re.findall(pattern=r"<td>(.*?)</td>", string=extracted_data, flags=re.S)
course_items = [item.strip() for item in items]
if len(course_items) != 11:
continue
course = Course(course_items[2],
course_items[6],
course_items[4],
course_items[1],
course_items[5],
course_items[7],
course_items[9],
course_items[10])
course_list.append(course)
events = []
for course in course_list:
events += course.get_events(self.__weekday_table, self.__course_time_table)
cal = Calendar()
cal.add("calscale", "GREGORIAN")
cal.add("version", "2.0")
cal.add("X-WR-CALNAME", "SHU Course Schedule")
cal.add("X-WR-TIMEZONE", "Asia/Shanghai")
for event in events:
cal.add_component(event)
cal_path = os.path.join(os.getcwd(), "Course Schedule.ics")
f = open(cal_path, "wb")
f.write(cal.to_ical())
f.close()
cros_platopen(cal_path)