fix: change URL

This commit is contained in:
Ting-Jun Wang 2022-07-26 23:19:52 +08:00
parent 1cf4193ecb
commit 70d41cc4bc
Signed by: snsd0805
GPG Key ID: 8DB0D22BC1217D33

View File

@ -6,7 +6,7 @@ from bs4 import BeautifulSoup as bs
USERNAME = ""
PASSWORD = ""
YEAR = 1102
YEAR = 1111
session = requests.Session()
@ -46,11 +46,11 @@ def curlDepartmentCourseTable(year):
print("取得所有課程資料:")
# 切換年度,應該是用 cookie 儲存當前閱覽的年份
url = 'https://ccweb.ncnu.edu.tw/student/aspmaker_course_opened_detail_viewlist.php?cmd=search&t=aspmaker_course_opened_detail_view&z_year=%3D&x_year={}&z_courseid=%3D&x_courseid=&z_cname=LIKE&x_cname=&z_deptid=%3D&x_deptid=&z_division=LIKE&x_division=&z_grade=%3D&x_grade=&z_teachers=LIKE&x_teachers=&z_not_accessible=LIKE&x_not_accessible='
url = 'https://ccweb6.ncnu.edu.tw/student/aspmaker_course_opened_detail_viewlist.php?cmd=search&t=aspmaker_course_opened_detail_view&z_year=%3D&x_year={}&z_courseid=%3D&x_courseid=&z_cname=LIKE&x_cname=&z_deptid=%3D&x_deptid=&z_division=LIKE&x_division=&z_grade=%3D&x_grade=&z_teachers=LIKE&x_teachers=&z_not_accessible=LIKE&x_not_accessible='
response = session.get(url.format(year))
# 取得 所有課程的 csv
response = session.get('https://ccweb.ncnu.edu.tw/student/aspmaker_course_opened_detail_viewlist.php?export=csv')
response = session.get('https://ccweb6.ncnu.edu.tw/student/aspmaker_course_opened_detail_viewlist.php?export=csv')
with open("allCourses.csv", "wb") as fp:
fp.write(response.content)
@ -73,8 +73,8 @@ def extractDepartmentCourseTable(year):
courseObj = {}
baseLink = "https://ccweb.ncnu.edu.tw/student/aspmaker_course_opened_detail_viewview.php?showdetail=&year={}&courseid={}&_class={}&modal=2"
courseObj['link'] = baseLink.format(year, data[1].zfill(6), data[2])
baseLink = "https://ccweb6.ncnu.edu.tw/student/aspmaker_course_opened_detail_viewlist.php?cmd=search&t=aspmaker_course_opened_detail_view&z_year=%3D&x_year={}&x_courseid={}"
courseObj['link'] = baseLink.format(year, data[1].zfill(6))
courseObj['year'] = data[0]
courseObj['number'] = data[1]
courseObj['class'] = data[2]
@ -84,7 +84,7 @@ def extractDepartmentCourseTable(year):
courseObj['grade'] = data[7]
courseObj['teacher'] = data[8]
courseObj['place'] = data[9]
courseObj['time'] = data[13]
courseObj['time'] = data[13].replace(' ', '')
courseObj['credit'] = data[14]
ans.append(courseObj)
@ -93,7 +93,7 @@ def extractDepartmentCourseTable(year):
json.dump(ans, fp, ensure_ascii=False)
def updateGeneralCourse():
with open("output.json") as fp:
with open("歷年課程資料/{}_output.json".format(YEAR)) as fp:
courses = json.load(fp)
with open("generalCourse.in") as fp:
@ -118,7 +118,7 @@ def updateGeneralCourse():
course['department'] = "99, 通識(未分類)"
print("{} {}".format(course['number'], course['name']))
with open("output.json", "w") as fp:
with open("歷年課程資料/{}_output.json".format(YEAR), "w") as fp:
json.dump(courses, fp, ensure_ascii=False)
@ -128,6 +128,7 @@ if __name__ == "__main__":
username = USERNAME
password = PASSWORD
if login(username, password):
print("登入成功!")
break
else:
print("登入失敗!")