#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import json
import datetime
# 强智教务管理系统
########################################
account = "填入学号"
password = "填入密码"
url = "https://jwgl.sdust.edu.cn/app.do"
########################################
class SW(object):
"""docstring for SW"""
def __init__(self, account, password, url):
super(SW, self).__init__()
self.url = url
self.account = account
self.password = password
self.session = self.login()
HEADERS = {
"User-Agent": "Mozilla/5.0 (Linux; U; Mobile; Android 6.0.1;C107-9 Build/FRF91 )",
"Referer": "http://www.baidu.com",
"Accept-encoding": "gzip, deflate, br",
"Accept-language": "zh-CN,zh-TW;q=0.8,zh;q=0.6,en;q=0.4,ja;q=0.2",
"Cache-control": "max-age=0"
}
def login(self):
params = {
"method": "authUser",
"xh": self.account,
"pwd": self.password
}
session = requests.Session()
req = session.get(self.url, params=params, timeout=5, headers=self.HEADERS)
s = json.loads(req.text)
#print(s)
if s["flag"] != "1": exit(0)
self.HEADERS["token"] = s["token"]
return session
def get_handle(self, params):
req = self.session.get(self.url, params=params, timeout=5, headers=self.HEADERS)
return req
def get_student_info(self):
params = {
"method": "getUserInfo",
"xh": self.account
}
req = self.get_handle(params)
print(req.text)
def get_current_time(self):
params = {
"method": "getCurrentTime",
"currDate": datetime.datetime.now().strftime("%Y-%m-%d")
}
req = self.get_handle(params)
print(req.text)
return req.text
def get_class_info(self, zc=-1):
s = json.loads(self.get_current_time())
params = {
"method": "getKbcxAzc",
"xnxqid": s["xnxqh"],
"zc": s["zc"] if zc == -1 else zc,
"xh": self.account
}
req = self.get_handle(params)
print(req.text)
def get_classroom_info(self, idleTime="allday"):
test1=datetime.datetime.now()
test2=test1.strftime("%Y-%m-%d")
params = {
"method": "getKxJscx",
"time": datetime.datetime.now().strftime("%Y-%m-%d"),
# "time": "2021-09-20",
"idleTime": idleTime
}
req = self.get_handle(params)
new_dict = json.loads(req.text)
return new_dict
print(req.text)
def get_grade_info(self, sy=""):
params = {
"method": "getCjcx",
"xh": self.account,
"xnxqid": sy
}
req = self.get_handle(params)
print("全部成绩" if sy == "" else sy)
s = json.loads(req.text)
if s[0] != None:
s = json.loads(req.text)
for x in s:
print("%s %d %s" % (str(x["zcj"]), x["xf"], x["kcmc"]))
print("绩点:" + str(self.get_gp(s)))
else:
print("空")
def get_exam_info(self):
params = {
"method": "getKscx",
"xh": self.account,
}
req = self.get_handle(params)
print(req.text)
def get_gp(self, data):
GP = 0.0
credit = 0.0
for x in data:
credit += x["xf"]
if x["zcj"] == "优":
GP += (4.5 * x["xf"])
elif x["zcj"] == "良":
GP += (3.5 * x["xf"])
elif x["zcj"] == "中":
GP += (2.5 * x["xf"])
elif x["zcj"] == "及格":
GP += (1.5 * x["xf"])
elif x["zcj"] == "不及格":
GP += 0
else:
if float(x["zcj"]) >= 60:
GP += (((float(x["zcj"]) - 60) / 10 + 1) * x["xf"])
return GP / credit
if __name__ == "__main__":
Q = SW(account, password, url)
# Q.get_student_info() #获取学生信息
# Q.get_current_time() #获取学年信息
# Q.get_class_info() #当前周次课表
# Q.get_class_info(3) #指定周次课表
listt=['占位0','0102','0304','0506','0708','0910']
chaxun=2#要查的空教室的节次,从1到5(1其实没用,没有6点到8点的课)
temp1 = Q.get_classroom_info(listt[chaxun-1]) # 空教室查询 "allday":全天 "am":上午 "pm":下午 "night":晚上 "0102":1.2节空教室 "0304":3.4节空教室
for i in temp1:
if i.get("jxl")=='青岛校区-S1楼':#青岛校区-1号楼
J1_1 = i.get("jsList")
break
temp2 = Q.get_classroom_info(listt[chaxun])
for i in temp2:
if i.get("jxl")=='青岛校区-S1楼':
J1_2 = i.get("jsList")
break
# retD = list(set(J1_2).difference(set(J1_1)))
# print(retD)
temp=[i.get("jsmc") for i in J1_1]
for j in J1_2[:]:
if j.get("jsmc") not in temp:#2时间段空而1时间段不空
print(j.get("jsmc"))
# Q.get_grade_info("2018-2019-1") #成绩查询 #无参数查询全部成绩
# Q.get_exam_info() #获取考试信息