本文整理匯總了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)