forked from luzy99/SEUAutoLogin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gpa.py
101 lines (88 loc) · 2.89 KB
/
gpa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# encoding=utf-8
import json
import argparse
from login import login
# 加载全局配置
with open("./config.json", "r", encoding="utf-8") as f:
configs = f.read()
configs = json.loads(configs)
def getGradeList(ss, terms):
ss.get("http://ehall.seu.edu.cn/appShow?appId=4768574631264620")
url = 'http://ehall.seu.edu.cn/jwapp/sys/cjcx/modules/cjcx/xscjcx.do'
params = {"querySetting": [{"name": "SHOWMAXCJ", "caption": "显示最高成绩", "linkOpt": "AND",
"builderList": "cbl_String", "builder": "equal", "value": 0, "value_display": "否"}],
"*order": "-XNXQDM,-KCH,-KXH",
"pageSize": 100,
"pageNumber": 1}
res = ss.post(url, data=params)
data = json.loads(res.text)['datas']['xscjcx']
print("成功读取 %s 门课程成绩" % data['totalSize'])
sum_xf = 0
sum_gpa = 0
term_xf = 0
term_gpa = 0
for item in data['rows']:
if item['KCXZDM_DISPLAY'] == '必修':
sum_xf += float(item['XF'])
sum_gpa += float(item['XF']) * computeGpa(item['ZCJ'])
if item['XNXQDM'] in terms:
term_xf += float(item['XF'])
term_gpa += float(item['XF']) * computeGpa(item['ZCJ'])
print("必修总学分:%f, 累计绩点:%f" % (sum_xf, sum_gpa / sum_xf))
if term_xf > 0:
print("Terms in ", terms)
print("学年必修总学分:%f, 学年绩点:%f" % (term_xf, term_gpa / term_xf))
def computeGpa(score):
score = float(score)
if score >= 96:
gpa = 4.8
elif score >= 93:
gpa = 4.5
elif score >= 90:
gpa = 4.0
elif score >= 86:
gpa = 3.8
elif score >= 83:
gpa = 3.5
elif score >= 80:
gpa = 3.0
elif score >= 76:
gpa = 2.8
elif score >= 73:
gpa = 2.5
elif score >= 70:
gpa = 2.0
elif score >= 66:
gpa = 1.8
elif score >= 63:
gpa = 1.5
elif score >= 60:
gpa = 1.0
else:
gpa = 0.0
return gpa
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Test for argparse')
parser.add_argument(
'--term', '-t', help='学期 20(计算20-21学年所有学期), 2020-2021-1(指定某一学期)', default='2020-2021-1')
args = parser.parse_args()
termList = ['2020-2021-1']
try:
termstr = str(args.term)
if len(termstr) == 11:
termList = [termstr]
elif len(termstr) == 2:
yy = int(termstr)
termList = []
for i in range(1, 5):
tmp = "20%d-20%d-%d" % (yy, yy + 1, i)
termList.append(tmp)
else:
print("参数错误!")
exit()
except Exception:
print("参数错误!")
exit()
ss = login(configs['user']['cardnum'], configs['user']['password'])
if ss:
getGradeList(ss, termList)