Skip to content

Commit

Permalink
fix 2nd select switching bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MXWXZ committed Dec 24, 2018
1 parent a3782ae commit eed29fe
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
11 changes: 11 additions & 0 deletions Protocol analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,22 @@ POST返回:
- 选课时间到进入选课页面

### 选课界面地址
- 抢选专用页面:`http://electsys.sjtu.edu.cn/edu/student/elect/secondRoundFP.aspx`
- 必修课地址(默认):`http://electsys.sjtu.edu.cn/edu/student/elect/speltyRequiredCourse.aspx`
- 选修课地址:`http://electsys.sjtu.edu.cn/edu/student/elect/speltyLimitedCourse.aspx `
- 通识课地址:`http://electsys.sjtu.edu.cn/edu/student/elect/speltyCommonCourse.aspx`
- 任选课地址:`http://electsys.sjtu.edu.cn/edu/student/elect/outSpeltyEP.aspx`

### 抢选专用页面
地址:[POST] `http://electsys.sjtu.edu.cn/edu/student/elect/secondRoundFP.aspx`
参数:
- `__VIEWSTATE`:ASPX参数
- `__VIEWSTATEGENERATOR`:ASPX参数
- `__EVENTVALIDATION`:ASPX参数
- `__EVENTARGUMENT`:空
- `__EVENTTARGET`:空
- `btnBxk`:定值`必修课`

### 主界面跳转
地址:[POST] `当前界面地址`\
参数:
Expand Down
31 changes: 21 additions & 10 deletions sjtu_automata/autoelect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
expend_page, list_teacher,
navpage, select_teacher, submit,
view_arrange, parse_renxuan, list_classid,
list_group, check_classtype, check_class_selected)
list_group, check_classtype, check_class_selected,
navmainpage)
from sjtu_automata.utils.exceptions import ParamError


Expand Down Expand Up @@ -167,22 +168,30 @@ def check_round_available(self, delay):
break
else:
if delay == 0:
echoerror('Elect round %d is unavailable!'%self.round)
echoerror('Elect round %d is unavailable!' % self.round)
exit()
else:
echoerror('Elect round %d is unavailable! Retry in %ds...' % (
self.round, delay))
sleep(delay)

def check_class_selected(self,classid):
if not ((self.classtype==1 and self.depth==0) or (self.classtype !=1 and self.depth==1)):
def nav_mainpage(self):
"""Nav to main page.
Only support for 2nd elect.
"""
echoinfo('Switching to main page...')
self.req, self.data = navmainpage(self.session, self.data)

def check_class_selected(self, classid):
if not ((self.classtype == 1 and self.depth == 0) or (self.classtype != 1 and self.depth == 1)):
echoerror('Please go to the right page!')
return False
ret= check_class_selected(self.req.text,classid)
ret = check_class_selected(self.req.text, classid)
if ret:
echoinfo('Class %s is selected!'%classid)
echoinfo('Class %s is selected!' % classid)
else:
echoinfo('Class %s is not selected!'%classid)
echoinfo('Class %s is not selected!' % classid)
return ret

def select_teacher(self, teacherid, delay):
Expand Down Expand Up @@ -218,7 +227,7 @@ def submit(self):
self.islogin = False

self.classtype = 1
self.session=self.req = self.classgroup = self.classid = self.data = self.params = self.grade = None
self.session = self.req = self.classgroup = self.classid = self.data = self.params = self.grade = None

self.depth = 0
self.tmpreq = self.tmpparams = self.tmpdata = None
Expand Down Expand Up @@ -309,6 +318,7 @@ def parse_cmd_qua(ui, cmdlist):
ui.round = int(cmdlist[1])
ui.login(cmdlist[2] == '1')
ui.check_round_available(int(cmdlist[3]))
ui.nav_mainpage()
else:
show_shell_help(True)
return True
Expand Down Expand Up @@ -427,7 +437,8 @@ def cli(interact, no_update, round, ocr, print_cookie, delay_elect, delay_login,
if elect:
for i in elect:
if ui.username:
echoinfo('Going for next elect, you must wait 30s for not being banned!')
echoinfo(
'Going for next elect, you must wait 30s for not being banned!')
sleep(31)
i = i.split('/')
cddir = 'cd '+' '.join(i[0:-2])
Expand All @@ -439,7 +450,7 @@ def cli(interact, no_update, round, ocr, print_cookie, delay_elect, delay_login,
echoinfo('Ignore elect...')
continue
else:
shell(ui,'cd '+i[-2])
shell(ui, 'cd '+i[-2])
shell(ui, 'elect %s %d' % (i[-1], delay_elect))
elif list_teacher:
lst = list_teacher.split('/')
Expand Down
23 changes: 23 additions & 0 deletions sjtu_automata/electsys/automata.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ def _parse_param(text):
return dict(item.split("=") for item in ret.split("&"))


def navmainpage(session, data):
"""go to main page.
Nav main page, only needed when round is 2!
Args:
session: requests session, login session.
round: int, elect round, 1 for 1st, 2 for 2nd, 3 for 3rd.
data: dict, post param with aspx param from last request.
Returns:
requests request.
dict, aspx param.
"""
pass_data = data
pass_data['__EVENTARGUMENT'] = pass_data['__EVENTTARGET'] = ''
pass_data['btnBxk'] = '必修课'
req, data = _request(
session, 'POST', 'http://electsys.sjtu.edu.cn/edu/student/elect/secondRoundFP.aspx', data=pass_data)

return req, data


def navpage(session, old_classtype, new_classtype, data):
"""nav from page to page.
Expand Down

0 comments on commit eed29fe

Please sign in to comment.