fix: merge py file

This commit is contained in:
snsd0805 2022-01-10 13:44:56 +08:00
parent 4485c14503
commit 1cf4193ecb
No known key found for this signature in database
GPG Key ID: 643DB36C1D5F3F10
2 changed files with 40 additions and 36 deletions

View File

@ -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)

View File

@ -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()