diff --git a/API_Usage.py b/API_Usage.py index 96a3afb..c974555 100644 --- a/API_Usage.py +++ b/API_Usage.py @@ -74,12 +74,20 @@ if ncnu.status: space() # ===== Test 取得所有缺曠課記錄 ===== - absenceLogs = ncnu.getAbsenceLog() + absenceLogs = ncnu.getAbsenceLogs() if absenceLogs: for log in absenceLogs: print(log) else: print("沒有任何缺曠課記錄") space() + + # ===== Test 獎懲紀錄 ===== + awardLogs = ncnu.getAwardLogs() + if awardLogs: + for log in awardLogs: + print(log) + else: + print("沒有任何獎懲紀錄") else: print("NCNU 教務系統登入失敗") diff --git a/api/ncnu.py b/api/ncnu.py index 75ebce6..07e3af6 100644 --- a/api/ncnu.py +++ b/api/ncnu.py @@ -123,7 +123,7 @@ class NCNU(): else: return None - def getAbsenceLog(self): + def getAbsenceLogs(self): response = self.session.get("https://ccweb.ncnu.edu.tw/student/absencelist.php") table = find(response, 'tbody') @@ -137,4 +137,19 @@ class NCNU(): 'time': data[4].text.replace('\n', '') } for data in (log.findAll('td') for log in logs)] else: - return None \ No newline at end of file + return None + + def getAwardLogs(self): + response = self.session.get('https://ccweb.ncnu.edu.tw/student/aspmaker_student_merit_viewlist.php?export=csv') + datas = response.text.split('\r\n')[1:-1] + + if len(datas) == 2: + return None + else: + return [{ + 'id': data[0], + 'semester': data[1], + 'award': data[2], + 'count': data[3], + 'content': data[4], + } for data in (data.replace('"', '').split(',') for data in datas)] \ No newline at end of file