fix: merge py file
This commit is contained in:
parent
4485c14503
commit
1cf4193ecb
@ -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)
|
|
||||||
|
|
||||||
46
getData.py
46
getData.py
@ -4,6 +4,10 @@ import os
|
|||||||
import csv
|
import csv
|
||||||
from bs4 import BeautifulSoup as bs
|
from bs4 import BeautifulSoup as bs
|
||||||
|
|
||||||
|
USERNAME = ""
|
||||||
|
PASSWORD = ""
|
||||||
|
YEAR = 1102
|
||||||
|
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
|
|
||||||
mainURL = "https://ccweb.ncnu.edu.tw/student/"
|
mainURL = "https://ccweb.ncnu.edu.tw/student/"
|
||||||
@ -88,16 +92,46 @@ def extractDepartmentCourseTable(year):
|
|||||||
with open("歷年課程資料/{}_output.json".format(year), 'w') as fp:
|
with open("歷年課程資料/{}_output.json".format(year), 'w') as fp:
|
||||||
json.dump(ans, fp, ensure_ascii=False)
|
json.dump(ans, fp, ensure_ascii=False)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def updateGeneralCourse():
|
||||||
year = input("年份: ")
|
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:
|
while True:
|
||||||
username = input("學號: ")
|
username = USERNAME
|
||||||
password = input("密碼: ")
|
password = PASSWORD
|
||||||
if login(username, password):
|
if login(username, password):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("登入失敗!")
|
print("登入失敗!")
|
||||||
|
|
||||||
curlDepartmentCourseTable(year)
|
curlDepartmentCourseTable(YEAR)
|
||||||
extractDepartmentCourseTable("1101")
|
extractDepartmentCourseTable(YEAR)
|
||||||
|
updateGeneralCourse()
|
||||||
Loading…
Reference in New Issue
Block a user