feat: 取得該課程的最新公告

This commit is contained in:
Ting-Jun Wang 2021-06-30 12:25:26 +08:00
parent fac7e0c7bc
commit e16e5d678f
Signed by: snsd0805
GPG Key ID: 8DB0D22BC1217D33
2 changed files with 21 additions and 7 deletions

View File

@ -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') ]

View File

@ -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)
print(work)
for anno in moodle.getAnnoInCourse('47555'):
print(anno)