From e16e5d678f09f48f4b085cf92ee994943ab6465a Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Wed, 30 Jun 2021 12:25:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=96=E5=BE=97=E8=A9=B2=E8=AA=B2?= =?UTF-8?q?=E7=A8=8B=E7=9A=84=E6=9C=80=E6=96=B0=E5=85=AC=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/moodle.py | 20 +++++++++++++++++--- main.py | 8 ++++---- 2 files changed, 21 insertions(+), 7 deletions(-) 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