diff --git a/api/moodle.py b/api/moodle.py index 9cae4ca..57bdfcb 100644 --- a/api/moodle.py +++ b/api/moodle.py @@ -114,10 +114,10 @@ class Moodle(): url = "https://moodle.ncnu.edu.tw/course/view.php?id={}" response = self.session.get(url.format(courseID)) # dateBlock = findAll(response, 'li', param={'class': 'section main clearfix'})[-2] - dateBlock = find(response, 'li', param={'class': 'section main clearfix current'}) + block = find(response, 'li', param={'class': 'section main clearfix current'}) - if dateBlock: - links = dateBlock.findAll('li') + if block: + links = block.findAll('li') return [{ 'name': " ".join( link.text.split(' ')[:-1] ), @@ -127,3 +127,17 @@ class Moodle(): else: return None + def getAnnoInCourse(self, courseID): + ''' + 使用 CourseID 取得最新公告 + block_news_items block + ''' + url = "https://moodle.ncnu.edu.tw/course/view.php?id={}" + response = self.session.get(url.format(courseID)) + block = find(response, 'div', param={'class': 'block_news_items block'}) + + return [{ + 'id': getUrlParam( + anno.find('a').get('href'), 'd' ), + 'title': anno.text + } for anno in block.findAll('div', 'info') ] \ No newline at end of file diff --git a/main.py b/main.py index 116a11b..c16ca88 100644 --- a/main.py +++ b/main.py @@ -6,8 +6,8 @@ if moodle.status: for c in moodle.getCourses("1092"): print(c) for e in moodle.getUpcomingEvents(): - print(e) - print(moodle.getEvent(e['id'])) - + print(e) for work in moodle.getWeekWorkInCourse('47562'): - print(work) \ No newline at end of file + print(work) + for anno in moodle.getAnnoInCourse('47555'): + print(anno) \ No newline at end of file