diff --git a/generalCourse.py b/generalCourse.py deleted file mode 100644 index bc27509..0000000 --- a/generalCourse.py +++ /dev/null @@ -1,30 +0,0 @@ -import json - -with open("output.json") as fp: - courses = json.load(fp) - -with open("generalCourse.in") as fp: - line = fp.readline() - while line: - count = 0 - line = line.split() - if len(line) == 2: - department = line[1] - else: - for course in courses: - if course['number'] == line[0]: - course['department'] = department - count += 1 - if count == 0 and len(line) != 2: - print("{} 可能輸入錯誤 - {}".format(line[0], department)) - line = fp.readline() - -print("還沒有對應到的課程:") -for course in courses: - if course['department'] == "99, 通識": - course['department'] = "99, 通識(未分類)" - print("{} {}".format(course['number'], course['name'])) - -with open("output.json", "w") as fp: - json.dump(courses, fp, ensure_ascii=False) - diff --git a/getData.py b/getData.py index 6227f34..458a5b5 100644 --- a/getData.py +++ b/getData.py @@ -4,6 +4,10 @@ import os import csv from bs4 import BeautifulSoup as bs +USERNAME = "" +PASSWORD = "" +YEAR = 1102 + session = requests.Session() mainURL = "https://ccweb.ncnu.edu.tw/student/" @@ -88,16 +92,46 @@ def extractDepartmentCourseTable(year): with open("歷年課程資料/{}_output.json".format(year), 'w') as fp: json.dump(ans, fp, ensure_ascii=False) -if __name__ == "__main__": - year = input("年份: ") +def updateGeneralCourse(): + with open("output.json") as fp: + courses = json.load(fp) + with open("generalCourse.in") as fp: + line = fp.readline() + while line: + count = 0 + line = line.split() + if len(line) == 2: + department = line[1] + else: + for course in courses: + if course['number'] == line[0]: + course['department'] = department + count += 1 + if count == 0 and len(line) != 2: + print("{} 可能輸入錯誤 - {}".format(line[0], department)) + line = fp.readline() + + print("還沒有對應到的課程:") + for course in courses: + if course['department'] == "99, 通識": + course['department'] = "99, 通識(未分類)" + print("{} {}".format(course['number'], course['name'])) + + with open("output.json", "w") as fp: + json.dump(courses, fp, ensure_ascii=False) + + + +if __name__ == "__main__": while True: - username = input("學號: ") - password = input("密碼: ") + username = USERNAME + password = PASSWORD if login(username, password): break else: print("登入失敗!") - curlDepartmentCourseTable(year) - extractDepartmentCourseTable("1101") + curlDepartmentCourseTable(YEAR) + extractDepartmentCourseTable(YEAR) + updateGeneralCourse() \ No newline at end of file