feat: 取得該課程的最新公告
This commit is contained in:
parent
fac7e0c7bc
commit
e16e5d678f
@ -114,10 +114,10 @@ class Moodle():
|
|||||||
url = "https://moodle.ncnu.edu.tw/course/view.php?id={}"
|
url = "https://moodle.ncnu.edu.tw/course/view.php?id={}"
|
||||||
response = self.session.get(url.format(courseID))
|
response = self.session.get(url.format(courseID))
|
||||||
# dateBlock = findAll(response, 'li', param={'class': 'section main clearfix'})[-2]
|
# 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:
|
if block:
|
||||||
links = dateBlock.findAll('li')
|
links = block.findAll('li')
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
'name': " ".join( link.text.split(' ')[:-1] ),
|
'name': " ".join( link.text.split(' ')[:-1] ),
|
||||||
@ -127,3 +127,17 @@ class Moodle():
|
|||||||
else:
|
else:
|
||||||
return None
|
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') ]
|
||||||
8
main.py
8
main.py
@ -6,8 +6,8 @@ if moodle.status:
|
|||||||
for c in moodle.getCourses("1092"):
|
for c in moodle.getCourses("1092"):
|
||||||
print(c)
|
print(c)
|
||||||
for e in moodle.getUpcomingEvents():
|
for e in moodle.getUpcomingEvents():
|
||||||
print(e)
|
print(e)
|
||||||
print(moodle.getEvent(e['id']))
|
|
||||||
|
|
||||||
for work in moodle.getWeekWorkInCourse('47562'):
|
for work in moodle.getWeekWorkInCourse('47562'):
|
||||||
print(work)
|
print(work)
|
||||||
|
for anno in moodle.getAnnoInCourse('47555'):
|
||||||
|
print(anno)
|
||||||
Loading…
Reference in New Issue
Block a user