Merge branch 'dev' into tkinter
This commit is contained in:
commit
83dc23e547
101
API_Usage.py
Normal file
101
API_Usage.py
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
from config import CONFIG
|
||||||
|
from api.moodle import Moodle
|
||||||
|
from api.ncnuMain import NcnuMain
|
||||||
|
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.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("沒有任何獎懲紀錄")
|
||||||
|
space()
|
||||||
|
|
||||||
|
# ===== Test 取得加選課程狀態 =====
|
||||||
|
logs = ncnu.getAddCourseLogs()
|
||||||
|
if logs:
|
||||||
|
for log in logs:
|
||||||
|
print(log)
|
||||||
|
space()
|
||||||
|
else:
|
||||||
|
print("NCNU 教務系統登入失敗")
|
||||||
46
api/ncnu.py
46
api/ncnu.py
@ -122,3 +122,49 @@ class NCNU():
|
|||||||
} for data in (score.findAll('td') for score in scores[1:])]
|
} for data in (score.findAll('td') for score in scores[1:])]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getAbsenceLogs(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
|
||||||
|
|
||||||
|
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)]
|
||||||
|
|
||||||
|
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)]
|
||||||
48
main.py
48
main.py
@ -1,48 +0,0 @@
|
|||||||
from config import CONFIG
|
|
||||||
from api.moodle import Moodle
|
|
||||||
from api.ncnuMain import NcnuMain
|
|
||||||
from api.ncnu import NCNU
|
|
||||||
|
|
||||||
def space():
|
|
||||||
print("\n" + "="*20 + "\n")
|
|
||||||
|
|
||||||
moodle = Moodle(CONFIG['moodle']['username'], CONFIG['moodle']['password'])
|
|
||||||
if moodle.status:
|
|
||||||
for c in moodle.getCourses("1092"):
|
|
||||||
print(c)
|
|
||||||
space()
|
|
||||||
for e in moodle.getUpcomingEvents():
|
|
||||||
print(e)
|
|
||||||
space()
|
|
||||||
for work in moodle.getWeekWorkInCourse('47562'):
|
|
||||||
print(work)
|
|
||||||
space()
|
|
||||||
for anno in moodle.getAnnoInCourse('47555'):
|
|
||||||
print(anno)
|
|
||||||
space()
|
|
||||||
else:
|
|
||||||
print("Moodle 登入失敗")
|
|
||||||
|
|
||||||
main = NcnuMain()
|
|
||||||
for anno in main.getAnno():
|
|
||||||
print(anno)
|
|
||||||
space()
|
|
||||||
|
|
||||||
ncnu = NCNU(CONFIG['NCNU']['username'], CONFIG['NCNU']['password'])
|
|
||||||
if ncnu.status:
|
|
||||||
if ncnu.getCourseTable('1092'):
|
|
||||||
print("1092 課表已經儲存到 ./1092課表.pdf")
|
|
||||||
else:
|
|
||||||
print("無法存取 1092 課表")
|
|
||||||
space()
|
|
||||||
scores = ncnu.getScoreSummary()
|
|
||||||
for c in scores['semesters']:
|
|
||||||
print(c)
|
|
||||||
print(scores['sum'])
|
|
||||||
space()
|
|
||||||
scores = ncnu.getScore('1092')
|
|
||||||
for i in scores:
|
|
||||||
print(i)
|
|
||||||
space()
|
|
||||||
else:
|
|
||||||
print("NCNU 教務系統登入失敗")
|
|
||||||
Loading…
Reference in New Issue
Block a user