Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ EnergySession | <http://10.168.55.50:8088> | 水表/电表查询
IDSSession | <http://ids.xidian.edu.cn/authserver> | 统一认证
RSBBSSession | <http://rsbbs.xidian.edu.cn> | 睿思论坛(外网)
WXSession | |
XKSession | <http://xk.xidian.edu.cn> | 选课系统
XKSession | <https://xk.xidian.edu.cn> | 选课系统
ZFWSession | <https://zfw.xidian.edu.cn> | 校园网流量购买/查询
SportsSession | <http://xd.5itsn.com> | 体适能查询

Expand Down
11 changes: 9 additions & 2 deletions libxduauth/sites/xk.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class XKSession(AuthSession):
user = {}
current_batch = {}

def __init__(self, username, password):
def __init__(self, username, password, keyword=''):
super().__init__(f'{self.cookie_name}_{username}')
self.username = username
cookies = requests.utils.dict_from_cookiejar(self.cookies)
Expand All @@ -36,11 +36,18 @@ def __init__(self, username, password):
if 'token' not in cookies or 'batch' not in cookies or not self.is_loggedin():
self.persist('token', self.login(username, password))
self.current_batch = next(filter(
lambda batch: batch['canSelect'] == '1',
lambda batch: (
batch['canSelect'] == '1' and
keyword in batch['name']
),
self.user['electiveBatchList']
))
self.persist('batch', json.dumps(self.current_batch))
cookies = requests.utils.dict_from_cookiejar(self.cookies)
self.cookies.update({'Authorization': cookies['token']})
self.get(self.BASE + '/elective/grablessons', params={
'batchId': self.current_batch['code'],
}) # wierd, yet mandatory.
self.headers.update({'Authorization': cookies['token']})

def persist(self, name, value):
Expand Down