From 913f235dfc7ba723d0d968b759f3668f79262664 Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Fri, 2 Jul 2021 01:29:12 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=BC=BA?= =?UTF-8?q?=E6=9B=A0=E8=AA=B2=E8=A8=98=E9=8C=84=E6=9F=A5=E8=A9=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/ncnu.py | 16 ++++++++++++++++ main.py | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/api/ncnu.py b/api/ncnu.py index 88f6cbd..75ebce6 100644 --- a/api/ncnu.py +++ b/api/ncnu.py @@ -120,5 +120,21 @@ class NCNU(): 'score': data[8].text.replace('\n',''), 'mandatory': data[9].text.replace('\n','') } for data in (score.findAll('td') for score in scores[1:])] + else: + return None + + def getAbsenceLog(self): + response = self.session.get("https://ccweb.ncnu.edu.tw/student/absencelist.php") + table = find(response, 'tbody') + + if table: + logs = table.findAll('tr') + return [{ + 'id': data[0].text.replace('\n', ''), + 'semester': data[1].text.replace('\n', ''), + 'classname': data[2].text.replace('\n', ''), + 'date': data[3].text.replace('\n', ''), + '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 diff --git a/main.py b/main.py index b0d94bc..232a690 100644 --- a/main.py +++ b/main.py @@ -44,5 +44,12 @@ if ncnu.status: for i in scores: print(i) space() + absenceLogs = ncnu.getAbsenceLog() + if absenceLogs: + for log in absenceLogs: + print(log) + else: + print("沒有任何缺曠課記錄") + space() else: print("NCNU 教務系統登入失敗") From 10f0b0293875df9134b6c9b9723e988652e4dd35 Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Fri, 2 Jul 2021 01:38:05 +0800 Subject: [PATCH 2/5] =?UTF-8?q?docs:=20=E6=96=B0=E5=A2=9EAPI=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=AF=84=E4=BE=8B=E8=A8=BB=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/main.py b/main.py index 232a690..96a3afb 100644 --- a/main.py +++ b/main.py @@ -6,44 +6,74 @@ from api.ncnu import NCNU def space(): print("\n" + "="*20 + "\n") +# =================== TEST Moodle API ========================== + +# ===== Test 登入 ===== moodle = Moodle(CONFIG['moodle']['username'], CONFIG['moodle']['password']) if moodle.status: + + # ===== Test 取得該學期課程資料 ===== for c in moodle.getCourses("1092"): print(c) space() + + # ===== Test 取得未來重要事件 ===== for e in moodle.getUpcomingEvents(): print(e) space() + + # ===== Test 取得課程在當週發布的物件 ( 文件、功課、BBB連結... 等) for work in moodle.getWeekWorkInCourse('47562'): print(work) space() + + # ===== TEST 取得該課程的最新公告 for anno in moodle.getAnnoInCourse('47555'): print(anno) space() else: print("Moodle 登入失敗") + + + +# =================== Test 暨大官網 API ========================== + +# ===== Test 取得暨大官網最新消息 ===== main = NcnuMain() for anno in main.getAnno(): print(anno) space() + + +# =================== Test 暨大教務系統 API ========================== + +# ===== Test 登入 ===== ncnu = NCNU(CONFIG['NCNU']['username'], CONFIG['NCNU']['password']) if ncnu.status: + + # ===== Test 下載課表 ===== if ncnu.getCourseTable('1092'): print("1092 課表已經儲存到 ./1092課表.pdf") else: print("無法存取 1092 課表") space() + + # ===== Test 取得各學期成績總覽 ===== scores = ncnu.getScoreSummary() for c in scores['semesters']: print(c) print(scores['sum']) space() + + # ===== Test 取得指定學期的成績列表 ===== scores = ncnu.getScore('1092') for i in scores: print(i) space() + + # ===== Test 取得所有缺曠課記錄 ===== absenceLogs = ncnu.getAbsenceLog() if absenceLogs: for log in absenceLogs: From ce2f90fb80bccda014c701029e64090014272ff2 Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Fri, 2 Jul 2021 01:39:08 +0800 Subject: [PATCH 3/5] =?UTF-8?q?style:=20=E6=9B=B4=E6=94=B9=E6=AA=94?= =?UTF-8?q?=E6=A1=88=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py => API_Usage.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename main.py => API_Usage.py (100%) diff --git a/main.py b/API_Usage.py similarity index 100% rename from main.py rename to API_Usage.py From 5dc8bd559ab43990d5d8dfbdacb99ef6389a0d45 Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Fri, 2 Jul 2021 02:29:08 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=8D=8E?= =?UTF-8?q?=E6=87=B2=E7=B4=80=E9=8C=84=E6=9F=A5=E8=A9=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_Usage.py | 10 +++++++++- api/ncnu.py | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) 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 From d720c32545d6b591768efe77895f77e4fe13cece Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Fri, 2 Jul 2021 02:52:13 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=E5=8A=A0=E9=81=B8=E8=AA=B2?= =?UTF-8?q?=E7=A8=8B=E6=9F=A5=E8=A9=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_Usage.py | 8 ++++++++ api/ncnu.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/API_Usage.py b/API_Usage.py index c974555..2916716 100644 --- a/API_Usage.py +++ b/API_Usage.py @@ -89,5 +89,13 @@ if ncnu.status: print(log) else: print("沒有任何獎懲紀錄") + space() + + # ===== Test 取得加選課程狀態 ===== + logs = ncnu.getAddCourseLogs() + if logs: + for log in logs: + print(log) + space() else: print("NCNU 教務系統登入失敗") diff --git a/api/ncnu.py b/api/ncnu.py index 07e3af6..85fd2ba 100644 --- a/api/ncnu.py +++ b/api/ncnu.py @@ -152,4 +152,19 @@ class NCNU(): 'award': data[2], 'count': data[3], 'content': data[4], + } for data in (data.replace('"', '').split(',') for data in datas)] + + def getAddCourseLogs(self): + response = self.session.get('https://ccweb.ncnu.edu.tw/student/applyaddcourselist.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], + 'classname': data[2]+data[3], + 'class': data[4], + 'check': data[5], } for data in (data.replace('"', '').split(',') for data in datas)] \ No newline at end of file